Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: CR"U"D request #130

Merged
merged 3 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ public ResponseEntity<ApiUtils.ApiResult<CareworkerResponse>> 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<ApiUtils.ApiResult<CareworkerResponse>> 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));

}
Expand All @@ -79,4 +79,4 @@ public ResponseEntity<ApiUtils.ApiResult<String>> deleteCareworker(
careworkerService.deleteCareworker(careworkerId, institution.getId());
return ResponseEntity.status(HttpStatus.NO_CONTENT).build();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,20 @@
@AllArgsConstructor
public class CareworkerRequest {

@Schema(description = "์š”์–‘๊ธฐ๊ด€์•„์ด๋””", example = "1")
@Schema(description = "์š”์–‘๊ธฐ๊ด€์•„์ด๋””", example = "11")
@NotNull(message = "์š”์–‘๊ธฐ๊ด€ ์•„์ด๋””๋Š” ํ•„์ˆ˜ ํ•ญ๋ชฉ์ž…๋‹ˆ๋‹ค.")
private Long institutionId;

@Schema(description = "์š”์–‘๋ณดํ˜ธ์‚ฌ ์ด๋ฆ„", example = "๋ฐ•๊ฒฝ์˜ฅ")
@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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,20 @@

public class CareworkerUpdateAdminRequest {

@Schema(description = "์š”์–‘๊ธฐ๊ด€์•„์ด๋””", example = "1")
@Schema(description = "์š”์–‘๊ธฐ๊ด€์•„์ด๋””", example = "11")
@NotNull(message = "์š”์–‘๊ธฐ๊ด€ ์•„์ด๋””๋Š” ํ•„์ˆ˜ ํ•ญ๋ชฉ์ž…๋‹ˆ๋‹ค.")
private Long institutionId;

@Schema(description = "์š”์–‘๋ณดํ˜ธ์‚ฌ ์ด๋ฆ„", example = "๋ฐ•๊ฒฝ์˜ฅ")
@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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
83 changes: 67 additions & 16 deletions src/main/java/dbdr/domain/careworker/service/CareworkerService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -18,7 +20,6 @@
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalTime;
import java.util.List;

@Service
@RequiredArgsConstructor
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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(),
Expand All @@ -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);
}


}
12 changes: 6 additions & 6 deletions src/main/java/dbdr/domain/excel/controller/ExcelController.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ private void validateFile(MultipartFile file) {
}
}

@Operation(summary = "์š”์–‘๊ด€๋ฆฌ์‚ฌ ์—‘์…€ ๋‹ค์šด๋กœ๋“œ")
@Operation(summary = "์š”์–‘๋ณดํ˜ธ์‚ฌ ์—‘์…€ ๋‹ค์šด๋กœ๋“œ")
@GetMapping("/careworker/download")
public ResponseEntity<byte[]> downloadCareworkerTemplate() {
byte[] data = excelDownloadService.generateCareworkerTemplate();
Expand Down Expand Up @@ -75,8 +75,8 @@ public ResponseEntity<byte[]> 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<CareworkerFileUploadResponse> uploadCareworkerData(
@Parameter(hidden = true) @LoginInstitution Institution institution,
Expand All @@ -86,7 +86,7 @@ public ResponseEntity<CareworkerFileUploadResponse> 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<GuardianFileUploadResponse> uploadGuardianData(
Expand All @@ -97,7 +97,7 @@ public ResponseEntity<GuardianFileUploadResponse> 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<RecipientFileUploadResponse> uploadRecipientData(
Expand All @@ -107,4 +107,4 @@ public ResponseEntity<RecipientFileUploadResponse> uploadRecipientData(
RecipientFileUploadResponse result = excelUploadService.uploadRecipientExcel(file, institution.getId());
return ResponseEntity.ok(result);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,4 @@ public ResponseEntity<ApiUtils.ApiResult<String>> deleteRecipient(
recipientService.deleteRecipientForCareworker(recipientId, careworker.getId());
return ResponseEntity.status(HttpStatus.NO_CONTENT).build();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,4 @@ public ResponseEntity<ApiUtils.ApiResult<String>> deleteRecipient(
recipientService.deleteRecipientForInstitution(recipientId, institution.getId());
return ResponseEntity.status(HttpStatus.NO_CONTENT).build();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand Down