diff --git a/src/main/java/dbdr/domain/careworker/controller/CareworkerAdminController.java b/src/main/java/dbdr/domain/careworker/controller/CareworkerAdminController.java index a5368d9..59d2247 100644 --- a/src/main/java/dbdr/domain/careworker/controller/CareworkerAdminController.java +++ b/src/main/java/dbdr/domain/careworker/controller/CareworkerAdminController.java @@ -26,6 +26,7 @@ public class CareworkerAdminController { private final CareworkerService careworkerService; + private final InstitutionService institutionService; @DbdrAuth(targetRole = Role.ADMIN) @Operation(summary = "전체 요양보호사 정보 조회", security = @SecurityRequirement(name = "JWT")) diff --git a/src/main/java/dbdr/domain/careworker/controller/CareworkerInstitutionController.java b/src/main/java/dbdr/domain/careworker/controller/CareworkerInstitutionController.java index 5708178..3b97745 100644 --- a/src/main/java/dbdr/domain/careworker/controller/CareworkerInstitutionController.java +++ b/src/main/java/dbdr/domain/careworker/controller/CareworkerInstitutionController.java @@ -48,13 +48,13 @@ public ResponseEntity> getCareworkerById( return ResponseEntity.ok(ApiUtils.success(careworker)) ; } - @DbdrAuth(targetRole = Role.INSTITUTION,authParam = AuthParam.LOGIN_INSTITUTION) + @DbdrAuth(targetRole = Role.INSTITUTION, authParam = AuthParam.LOGIN_INSTITUTION) @Operation(summary = "요양보호사 추가", security = @SecurityRequirement(name = "JWT")) @PostMapping public ResponseEntity> createCareworker( @Parameter(hidden = true) @LoginInstitution Institution institution, @Valid @RequestBody CareworkerRequest careworkerDTO) { - CareworkerResponse newCareworker = careworkerService.createCareworker(careworkerDTO); + CareworkerResponse newCareworker = careworkerService.createCareworkerInstitution(careworkerDTO, institution.getId()); return ResponseEntity.status(HttpStatus.CREATED).body(ApiUtils.success(newCareworker)); } @@ -79,4 +79,4 @@ public ResponseEntity> deleteCareworker( careworkerService.deleteCareworker(careworkerId, institution.getId()); return ResponseEntity.status(HttpStatus.NO_CONTENT).build(); } -} +} \ No newline at end of file diff --git a/src/main/java/dbdr/domain/careworker/dto/request/CareworkerRequest.java b/src/main/java/dbdr/domain/careworker/dto/request/CareworkerRequest.java index de252e7..3fc546e 100644 --- a/src/main/java/dbdr/domain/careworker/dto/request/CareworkerRequest.java +++ b/src/main/java/dbdr/domain/careworker/dto/request/CareworkerRequest.java @@ -14,7 +14,7 @@ @AllArgsConstructor public class CareworkerRequest { - @Schema(description = "요양기관아이디", example = "1") + @Schema(description = "요양기관아이디", example = "11") @NotNull(message = "요양기관 아이디는 필수 항목입니다.") private Long institutionId; @@ -22,12 +22,12 @@ public class CareworkerRequest { @NotBlank(message = "이름은 필수 항목입니다.") private String name; - @Schema(description = "요양보호사 이메일", example = "care@email.com") + @Schema(description = "요양보호사 이메일", example = "carecare1@email.com") @NotBlank(message = "이메일은 필수 항목입니다.") @Email(message = "올바르지 않은 형식입니다.") private String email; - @Schema(description = "요양보호사 휴대폰 번호", example = "01022223333") + @Schema(description = "요양보호사 휴대폰 번호", example = "01012349999") @NotBlank(message = "휴대폰 번호는 필수 항목입니다.") @Pattern(regexp = "010\\d{8}", message = "010XXXXXXXX형식으로 입력해주세요.") private String phone; diff --git a/src/main/java/dbdr/domain/careworker/dto/request/CareworkerUpdateAdminRequest.java b/src/main/java/dbdr/domain/careworker/dto/request/CareworkerUpdateAdminRequest.java index af9d743..de5c89f 100644 --- a/src/main/java/dbdr/domain/careworker/dto/request/CareworkerUpdateAdminRequest.java +++ b/src/main/java/dbdr/domain/careworker/dto/request/CareworkerUpdateAdminRequest.java @@ -16,7 +16,7 @@ public class CareworkerUpdateAdminRequest { - @Schema(description = "요양기관아이디", example = "1") + @Schema(description = "요양기관아이디", example = "11") @NotNull(message = "요양기관 아이디는 필수 항목입니다.") private Long institutionId; @@ -24,12 +24,12 @@ public class CareworkerUpdateAdminRequest { @NotBlank(message = "이름은 필수 항목입니다.") private String name; - @Schema(description = "요양보호사 이메일", example = "care@email.com") + @Schema(description = "요양보호사 이메일", example = "carecare20@email.com") @NotBlank(message = "이메일은 필수 항목입니다.") @Email(message = "올바르지 않은 형식입니다.") private String email; - @Schema(description = "요양보호사 휴대폰 번호", example = "01022223333") + @Schema(description = "요양보호사 휴대폰 번호", example = "01057573333") @NotBlank(message = "휴대폰 번호는 필수 항목입니다.") @Pattern(regexp = "010\\d{8}", message = "010XXXXXXXX형식으로 입력해주세요.") private String phone; diff --git a/src/main/java/dbdr/domain/careworker/dto/request/CareworkerUpdateInstitutionRequest.java b/src/main/java/dbdr/domain/careworker/dto/request/CareworkerUpdateInstitutionRequest.java index e225e6c..36bb1e0 100644 --- a/src/main/java/dbdr/domain/careworker/dto/request/CareworkerUpdateInstitutionRequest.java +++ b/src/main/java/dbdr/domain/careworker/dto/request/CareworkerUpdateInstitutionRequest.java @@ -18,12 +18,12 @@ public class CareworkerUpdateInstitutionRequest { @NotBlank(message = "이름은 필수 항목입니다.") private String name; - @Schema(description = "요양보호사 이메일", example = "care@email.com") + @Schema(description = "요양보호사 이메일", example = "carecare20@email.com") @NotBlank(message = "이메일은 필수 항목입니다.") @Email(message = "올바르지 않은 형식입니다.") private String email; - @Schema(description = "요양보호사 휴대폰 번호", example = "01022223333") + @Schema(description = "요양보호사 휴대폰 번호", example = "01057573332") @NotBlank(message = "휴대폰 번호는 필수 항목입니다.") @Pattern(regexp = "010\\d{8}", message = "010XXXXXXXX형식으로 입력해주세요.") private String phone; diff --git a/src/main/java/dbdr/domain/careworker/service/CareworkerService.java b/src/main/java/dbdr/domain/careworker/service/CareworkerService.java index 678a425..aa902bd 100644 --- a/src/main/java/dbdr/domain/careworker/service/CareworkerService.java +++ b/src/main/java/dbdr/domain/careworker/service/CareworkerService.java @@ -2,6 +2,8 @@ import dbdr.domain.careworker.dto.CareworkerMapper; import dbdr.domain.careworker.dto.request.CareworkerRequest; +import dbdr.domain.careworker.dto.request.CareworkerUpdateAdminRequest; +import dbdr.domain.careworker.dto.request.CareworkerUpdateInstitutionRequest; import dbdr.domain.careworker.dto.request.CareworkerUpdateRequest; import dbdr.domain.careworker.dto.response.CareworkerMyPageResponse; import dbdr.domain.careworker.dto.response.CareworkerResponse; @@ -18,7 +20,6 @@ import org.springframework.transaction.annotation.Transactional; import java.time.LocalTime; -import java.util.List; @Service @RequiredArgsConstructor @@ -81,6 +82,24 @@ public CareworkerResponse createCareworker(CareworkerRequest careworkerRequestDT return careworkerMapper.toResponse(careworker); } + @Transactional + public CareworkerResponse createCareworkerInstitution(CareworkerRequest careworkerRequestDTO, Long institutionId) { + + if (!careworkerRequestDTO.getInstitutionId().equals(institutionId)) { + throw new ApplicationException(ApplicationError.ACCESS_NOT_ALLOWED); + } + ensureUniqueEmail(careworkerRequestDTO.getEmail()); + ensureUniquePhone(careworkerRequestDTO.getPhone()); + + Careworker careworker = careworkerMapper.toEntity(careworkerRequestDTO); + + careworkerRepository.save(careworker); + alarmService.createCareworkerAlarm(careworker); + + return careworkerMapper.toResponse(careworker); + } + + @Transactional public CareworkerResponse updateCareworker(Long careworkerId, CareworkerRequest request) { ensureUniquePhoneButNotId(request.getPhone(), careworkerId); @@ -96,22 +115,32 @@ public CareworkerResponse updateCareworker(Long careworkerId, CareworkerRequest } @Transactional - public CareworkerResponse updateCareworkerByAdmin(Long careworkerId, CareworkerRequest request) { + public CareworkerResponse updateCareworkerByAdmin(Long careworkerId, CareworkerUpdateAdminRequest request) { ensureUniquePhoneButNotId(request.getPhone(), careworkerId); ensureUniqueEmailButNotId(request.getEmail(), careworkerId); + Careworker careworker = findCareworkerById(careworkerId); Institution institution = institutionService.getInstitutionById(request.getInstitutionId()); - /*if (institution == null) { - throw new ApplicationException(ApplicationError.INSTITUTION_NOT_FOUND); - }*/ careworker.updateInstitution(institution); - careworker.updateCareworker(careworkerMapper.toEntity(request)); + careworker.updateCareworker(toEntity(request)); return careworkerMapper.toResponse(careworker); } + // 요양원용 업데이트 + @Transactional + public CareworkerResponse updateCareworkerByInstitution(Long careworkerId, CareworkerUpdateInstitutionRequest request) { + ensureUniquePhoneButNotId(request.getPhone(), careworkerId); + ensureUniqueEmailButNotId(request.getEmail(), careworkerId); + Careworker careworker = findCareworkerById(careworkerId); + + + careworker.updateCareworker(toEntity(request, careworker)); + return careworkerMapper.toResponse(careworker); + } + @Transactional public void deleteCareworker(Long careworkerId, Long institutionId) { Careworker careworker = findCareworkerById(careworkerId); @@ -190,15 +219,6 @@ public Careworker findByPhone(String phoneNumber) { return careworkerRepository.findByPhone(phoneNumber).orElse(null); } - @Transactional - public void updateLineUserId(String userId, String phoneNumber) { - Careworker careworker = findByPhone(phoneNumber); - careworker.updateLineUserId(userId); - careworkerRepository.save(careworker); - } - - - private CareworkerMyPageResponse toMyPageResponseDTO(Careworker careworker) { return new CareworkerMyPageResponse( careworker.getName(), @@ -208,4 +228,35 @@ private CareworkerMyPageResponse toMyPageResponseDTO(Careworker careworker) { careworker.getWorkingDays() ); } -} + + public Careworker toEntity(CareworkerUpdateAdminRequest request) { + Institution institution = institutionService.getInstitutionById(request.getInstitutionId()); + return Careworker.builder() + .institution(institution) + .name(request.getName()) + .email(request.getEmail()) + .phone(request.getPhone()) + .build(); + } + + // 요양원 요청을 Careworker 엔티티로 변환하는 메서드 (institutionId 수정 없음) + public Careworker toEntity(CareworkerUpdateInstitutionRequest request, Careworker existingCareworker) { + existingCareworker.updateCareworker( + Careworker.builder() + .name(request.getName()) + .email(request.getEmail()) + .phone(request.getPhone()) + .build() + ); + return existingCareworker; + } + + @Transactional + public void updateLineUserId(String userId, String phoneNumber) { + Careworker careworker = findByPhone(phoneNumber); + careworker.updateLineUserId(userId); + careworkerRepository.save(careworker); + } + + +} \ No newline at end of file diff --git a/src/main/java/dbdr/domain/excel/controller/ExcelController.java b/src/main/java/dbdr/domain/excel/controller/ExcelController.java index 0d77cce..6382803 100644 --- a/src/main/java/dbdr/domain/excel/controller/ExcelController.java +++ b/src/main/java/dbdr/domain/excel/controller/ExcelController.java @@ -44,7 +44,7 @@ private void validateFile(MultipartFile file) { } } - @Operation(summary = "요양관리사 엑셀 다운로드") + @Operation(summary = "요양보호사 엑셀 다운로드") @GetMapping("/careworker/download") public ResponseEntity downloadCareworkerTemplate() { byte[] data = excelDownloadService.generateCareworkerTemplate(); @@ -75,8 +75,8 @@ public ResponseEntity downloadRecipientTemplate() { .body(data); } - @DbdrAuth(targetRole = Role.INSTITUTION,authParam = AuthParam.LOGIN_INSTITUTION) - @Operation(summary = "요양관리사 엑셀 업로드") + @DbdrAuth(targetRole = Role.INSTITUTION, authParam = AuthParam.LOGIN_INSTITUTION) + @Operation(summary = "요양보호사 엑셀 업로드") @PostMapping("/careworker/upload") public ResponseEntity uploadCareworkerData( @Parameter(hidden = true) @LoginInstitution Institution institution, @@ -86,7 +86,7 @@ public ResponseEntity uploadCareworkerData( return ResponseEntity.ok(result); } - @DbdrAuth(targetRole = Role.INSTITUTION,authParam = AuthParam.LOGIN_INSTITUTION) + @DbdrAuth(targetRole = Role.INSTITUTION, authParam = AuthParam.LOGIN_INSTITUTION) @Operation(summary = "보호자 엑셀 업로드") @PostMapping("/guardian/upload") public ResponseEntity uploadGuardianData( @@ -97,7 +97,7 @@ public ResponseEntity uploadGuardianData( return ResponseEntity.ok(result); } - @DbdrAuth(targetRole = Role.INSTITUTION,authParam = AuthParam.LOGIN_INSTITUTION) + @DbdrAuth(targetRole = Role.INSTITUTION, authParam = AuthParam.LOGIN_INSTITUTION) @Operation(summary = "돌봄대상자 엑셀 업로드") @PostMapping("/recipient/upload") public ResponseEntity uploadRecipientData( @@ -107,4 +107,4 @@ public ResponseEntity uploadRecipientData( RecipientFileUploadResponse result = excelUploadService.uploadRecipientExcel(file, institution.getId()); return ResponseEntity.ok(result); } -} +} \ No newline at end of file diff --git a/src/main/java/dbdr/domain/recipient/controller/RecipientCareworkerController.java b/src/main/java/dbdr/domain/recipient/controller/RecipientCareworkerController.java index f6d49f3..591aa31 100644 --- a/src/main/java/dbdr/domain/recipient/controller/RecipientCareworkerController.java +++ b/src/main/java/dbdr/domain/recipient/controller/RecipientCareworkerController.java @@ -79,4 +79,4 @@ public ResponseEntity> deleteRecipient( recipientService.deleteRecipientForCareworker(recipientId, careworker.getId()); return ResponseEntity.status(HttpStatus.NO_CONTENT).build(); } -} +} \ No newline at end of file diff --git a/src/main/java/dbdr/domain/recipient/controller/RecipientInstitutionController.java b/src/main/java/dbdr/domain/recipient/controller/RecipientInstitutionController.java index 6976d4a..8d6fd7e 100644 --- a/src/main/java/dbdr/domain/recipient/controller/RecipientInstitutionController.java +++ b/src/main/java/dbdr/domain/recipient/controller/RecipientInstitutionController.java @@ -78,4 +78,4 @@ public ResponseEntity> deleteRecipient( recipientService.deleteRecipientForInstitution(recipientId, institution.getId()); return ResponseEntity.status(HttpStatus.NO_CONTENT).build(); } -} +} \ No newline at end of file diff --git a/src/main/java/dbdr/domain/recipient/dto/request/RecipientRequest.java b/src/main/java/dbdr/domain/recipient/dto/request/RecipientRequest.java index 667d627..7be73e4 100644 --- a/src/main/java/dbdr/domain/recipient/dto/request/RecipientRequest.java +++ b/src/main/java/dbdr/domain/recipient/dto/request/RecipientRequest.java @@ -32,7 +32,7 @@ public class RecipientRequest { @NotBlank(message = "장기요양등급은 필수 항목입니다.") private String careLevel; - @Schema(description = "장기요양번호", example = "200000") + @Schema(description = "장기요양번호", example = "L0000000000-300") @NotBlank(message = "장기요양번호는 필수 항목입니다.") @Pattern(regexp = "^[A-Z0-9-]+$", message = "올바르지 않은 형식입니다.") private String careNumber; @@ -45,19 +45,19 @@ public class RecipientRequest { @NotBlank(message = "요양기관이름은 필수 항목입니다.") private String institution; - @Schema(description = "돌봄대상자가 속해있는 요양기관 번호", example = "1234") + @Schema(description = "돌봄대상자가 속해있는 요양기관 번호", example = "777999") @NotNull(message = "요양기관번호는 필수 항목입니다.") private Long institutionNumber; - @Schema(description = "돌봄대상자가 속해있는 요양원 아이디", example = "1") + @Schema(description = "돌봄대상자가 속해있는 요양원 아이디", example = "11") @NotNull(message = "요양기관 ID는 필수 항목입니다.") private Long institutionId; - @Schema(description = "돌봄대상자의 요양보호사 아이디", example = "1") + @Schema(description = "돌봄대상자의 요양보호사 아이디", example = "8") @NotNull(message = "요양보호사 ID는 필수 항목입니다.") private Long careworkerId; - @Schema(description = "돌봄대상자의 보호자 아이디", example = "1") + @Schema(description = "돌봄대상자의 보호자 아이디", example = "11") @NotNull(message = "보호자 ID는 필수 항목입니다.") private Long guardianId; -} +} \ No newline at end of file diff --git a/src/main/java/dbdr/domain/recipient/dto/request/RecipientUpdateCareworkerRequest.java b/src/main/java/dbdr/domain/recipient/dto/request/RecipientUpdateCareworkerRequest.java index f6adf27..0cc62cd 100644 --- a/src/main/java/dbdr/domain/recipient/dto/request/RecipientUpdateCareworkerRequest.java +++ b/src/main/java/dbdr/domain/recipient/dto/request/RecipientUpdateCareworkerRequest.java @@ -32,7 +32,7 @@ public class RecipientUpdateCareworkerRequest { @NotBlank(message = "장기요양등급은 필수 항목입니다.") private String careLevel; - @Schema(description = "장기요양번호", example = "200000") + @Schema(description = "장기요양번호", example = "123400000") @NotBlank(message = "장기요양번호는 필수 항목입니다.") @Pattern(regexp = "^[A-Z0-9-]+$", message = "올바르지 않은 형식입니다.") private String careNumber; diff --git a/src/main/java/dbdr/domain/recipient/dto/request/RecipientUpdateInstitutionRequest.java b/src/main/java/dbdr/domain/recipient/dto/request/RecipientUpdateInstitutionRequest.java index 5fc9169..68e150d 100644 --- a/src/main/java/dbdr/domain/recipient/dto/request/RecipientUpdateInstitutionRequest.java +++ b/src/main/java/dbdr/domain/recipient/dto/request/RecipientUpdateInstitutionRequest.java @@ -32,7 +32,7 @@ public class RecipientUpdateInstitutionRequest { @NotBlank(message = "장기요양등급은 필수 항목입니다.") private String careLevel; - @Schema(description = "장기요양번호", example = "200000") + @Schema(description = "장기요양번호", example = "123400000") @NotBlank(message = "장기요양번호는 필수 항목입니다.") @Pattern(regexp = "^[A-Z0-9-]+$", message = "올바르지 않은 형식입니다.") private String careNumber; @@ -41,11 +41,11 @@ public class RecipientUpdateInstitutionRequest { @NotNull(message = "입소일은 필수 항목입니다.") private LocalDate startDate; - @Schema(description = "돌봄대상자의 요양보호사 아이디", example = "1") + @Schema(description = "돌봄대상자의 요양보호사 아이디", example = "8") @NotNull(message = "요양보호사 ID는 필수 항목입니다.") private Long careworkerId; - @Schema(description = "돌봄대상자의 보호자 아이디", example = "1") + @Schema(description = "돌봄대상자의 보호자 아이디", example = "11") @NotNull(message = "보호자 ID는 필수 항목입니다.") private Long guardianId; diff --git a/src/main/java/dbdr/domain/recipient/service/RecipientService.java b/src/main/java/dbdr/domain/recipient/service/RecipientService.java index b4efa9f..e97b585 100644 --- a/src/main/java/dbdr/domain/recipient/service/RecipientService.java +++ b/src/main/java/dbdr/domain/recipient/service/RecipientService.java @@ -56,6 +56,9 @@ public RecipientResponse createRecipient(RecipientRequest recipientDTO) { throw new ApplicationException(ApplicationError.ACCESS_NOT_ALLOWED); } Guardian guardian = guardianService.findGuardianById(recipientDTO.getGuardianId()); + if (!guardian.getInstitution().getId().equals(institution.getId())) { + throw new ApplicationException(ApplicationError.ACCESS_NOT_ALLOWED); + } Recipient recipient = new Recipient(recipientDTO, institution, careworker, guardian); recipientRepository.save(recipient); @@ -81,7 +84,11 @@ public RecipientResponse updateRecipientForAdmin(Long recipientId, RecipientRequ throw new ApplicationException(ApplicationError.ACCESS_NOT_ALLOWED); } Guardian guardian = guardianService.findGuardianById(recipientDTO.getGuardianId()); - //관리자는 요양원, 요양보호사 업데이트 가능 + // guardian가 해당 Institution에 속하는지 확인 + if (!guardian.getInstitution().getId().equals(institution.getId())) { + throw new ApplicationException(ApplicationError.ACCESS_NOT_ALLOWED); + } + //관리자는 요양원, 요양보호사, 보호자 업데이트 가능 recipient.updateRecipient(recipientDTO); recipient.updateRecipientForAdmin(recipientDTO, institution, careworker, guardian); @@ -172,6 +179,9 @@ public RecipientResponse createRecipientForInstitution(RecipientRequest recipien } Guardian guardian = guardianService.findGuardianById(recipientDTO.getGuardianId()); + if (!guardian.getInstitution().getId().equals(institution.getId())) { + throw new ApplicationException(ApplicationError.ACCESS_NOT_ALLOWED); + } Recipient recipient = new Recipient(recipientDTO, institution, careworker, guardian); recipientRepository.save(recipient); return toResponse(recipient); @@ -202,6 +212,9 @@ public RecipientResponse updateRecipientForInstitution(Long recipientId, Recipie } Guardian guardian = guardianService.findGuardianById(recipientDTO.getGuardianId()); + if (!guardian.getInstitution().getId().equals(institutionId)) { + throw new ApplicationException(ApplicationError.ACCESS_NOT_ALLOWED); + } // 요양원은 본인 요양원에 속한 careworker, guardian 업데이트 가능 recipient.updateRecipientForInstitution(recipientDTO, careworker, guardian);