Skip to content

Commit

Permalink
[PDS-213] fix: 비품 관리 직원 에러처리 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
chaerlo127 committed Nov 30, 2023
1 parent 8bfddbf commit 24ab9f3
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.example.pladialmserver.equipment.repository;

import com.example.pladialmserver.equipment.entity.Equipment;
import com.example.pladialmserver.user.entity.User;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
Expand All @@ -12,4 +13,5 @@
public interface EquipmentRepository extends JpaRepository<Equipment, Long> {
Optional<Equipment> findByEquipmentIdAndIsEnable(Long equipmentId, Boolean isEnable);
Page<Equipment> findByNameContainsAndIsEnable(String cond, Pageable pageable, Boolean isEnable);
Boolean existsByUserAndIsEnable(User user, Boolean isEnable);
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ public enum BaseResponseCode {
EXISTS_PHONE("U0019", HttpStatus.CONFLICT, "존재하는 휴대폰번호입니다."),
NOT_EMPTY_AFFILIATION("U0020", HttpStatus.BAD_REQUEST, "소속을 입력해주세요."),
AFFILIATION_NOT_FOUND("U0021", HttpStatus.NOT_FOUND, "소속을 찾을 수 없습니다."),
EXISTS_CAR_AMDIN_USER("U0022", HttpStatus.BAD_REQUEST, "차량을 관리하는 직원입니다. 관리자를 변경해주세요."),
EXISTS_RESOURCE_AMDIN_USER("U0023", HttpStatus.BAD_REQUEST, "장비을 관리하는 직원입니다. 관리자를 변경해주세요."),
EXISTS_CAR_ADMIN_USER("U0022", HttpStatus.BAD_REQUEST, "차량을 관리하는 직원입니다. 관리자를 변경해주세요."),
EXISTS_RESOURCE_ADMIN_USER("U0023", HttpStatus.BAD_REQUEST, "장비을 관리하는 직원입니다. 관리자를 변경해주세요."),
EXISTS_EQUIPMENT_ADMIN_USER("U0024", HttpStatus.BAD_REQUEST, "비품을 관리하는 직원입니다. 관리자를 변경해주세요."),

// Booking
DATE_OR_TIME_IS_NULL("B0001", HttpStatus.BAD_REQUEST, "날짜와 시간을 모두 입력해주세요."),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public ResponseCustom<UserRes> getUserInfo(@Account User user,
@Operation(summary = "직원 탈퇴 (장채은)", description = "직원을 탈퇴 시킨다.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "(S0001)직원 탈퇴 성공"),
@ApiResponse(responseCode = "400", description = "(U0022)차량을 관리하는 직원입니다. 관리자를 변경해주세요.\n (U0023)장비을 관리하는 직원입니다. 관리자를 변경해주세요."),
@ApiResponse(responseCode = "400", description = "(U0022)차량을 관리하는 직원입니다. 관리자를 변경해주세요.\n (U0023)장비을 관리하는 직원입니다. 관리자를 변경해주세요.\n(U0024)비품을 관리하는 직원입니다. 관리자를 변경해주세요."),
@ApiResponse(responseCode = "403", description = "(G0002)접근 권한이 없습니다.", content = @Content(schema = @Schema(implementation = ResponseCustom.class))),
@ApiResponse(responseCode = "404", description = "(U0001)사용자를 찾을 수 없습니다.[관리자 및 직원 모두]", content = @Content(schema = @Schema(implementation = ResponseCustom.class)))
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public ResponseCustom<ResponsibilityListRes> getResponsibilityList(
@Operation(summary = "직원 탈퇴 (장채은)", description = "직원을 탈퇴한다.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "(S0001)직원 탈퇴 성공"),
@ApiResponse(responseCode = "400", description = "(U0022)차량을 관리하는 직원입니다. 관리자를 변경해주세요.\n (U0023)장비을 관리하는 직원입니다. 관리자를 변경해주세요."),
@ApiResponse(responseCode = "400", description = "(U0022)차량을 관리하는 직원입니다. 관리자를 변경해주세요.\n (U0023)장비을 관리하는 직원입니다. 관리자를 변경해주세요.\n(U0024)비품을 관리하는 직원입니다. 관리자를 변경해주세요."),
@ApiResponse(responseCode = "404", description = "(U0001)사용자를 찾을 수 없습니다.", content = @Content(schema = @Schema(implementation = ResponseCustom.class)))
})
@DeleteMapping("")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.example.pladialmserver.user.service;

import com.example.pladialmserver.equipment.repository.EquipmentRepository;
import com.example.pladialmserver.global.Constants;
import com.example.pladialmserver.global.exception.BaseException;
import com.example.pladialmserver.global.utils.EmailUtil;
Expand All @@ -25,7 +26,6 @@
import org.apache.commons.lang3.RandomStringUtils;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand All @@ -45,6 +45,7 @@ public class UserService {
private final DepartmentRepository departmentRepository;
private final PushNotificationRepository notificationRepository;
private final CarRepository carRepository;
private final EquipmentRepository equipmentRepository;
private final ResourceRepository resourceRepository;
private final AffiliationRepository affiliationRepository;
private final PasswordEncoder passwordEncoder;
Expand Down Expand Up @@ -121,8 +122,9 @@ public ResponsibilityListRes getResponsibilityList(String name) {
// 직원 접근 탈퇴
public void resignUser(User user) {
// 탈퇴하려는 회원이 장비, 차량 관리자인 경우 애러처리
if (resourceRepository.existsByUserAndIsEnable(user, true)) throw new BaseException(EXISTS_RESOURCE_AMDIN_USER);
if (carRepository.existsByUserAndIsEnable(user, true)) throw new BaseException(EXISTS_CAR_AMDIN_USER);
if (resourceRepository.existsByUserAndIsEnable(user, true)) throw new BaseException(EXISTS_RESOURCE_ADMIN_USER);
if (carRepository.existsByUserAndIsEnable(user, true)) throw new BaseException(EXISTS_CAR_ADMIN_USER);
if (equipmentRepository.existsByUserAndIsEnable(user, true)) throw new BaseException(EXISTS_CAR_ADMIN_USER);
jwtUtil.deleteRefreshToken(user.getUserId());
userRepository.delete(user);
}
Expand Down

0 comments on commit 24ab9f3

Please sign in to comment.