From 447df1e001ed36bf89da5c4f7855f53fd90a5090 Mon Sep 17 00:00:00 2001 From: suhyun Date: Thu, 14 Sep 2023 07:17:40 +0900 Subject: [PATCH] =?UTF-8?q?Feature:=20=EB=B8=8C=EB=A6=AC=EB=8D=94=20?= =?UTF-8?q?=EC=9D=B8=EC=A6=9D=EB=B0=9B=EA=B8=B0=20=EB=B0=8F=20=EB=A7=A4?= =?UTF-8?q?=EC=B9=AD=20=EC=8B=A0=EC=B2=AD=20api=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/matching/dto/MatchingFormDto.java | 10 +++++-- .../member/repository/AdminRepository.java | 2 ++ .../controller/VerificationController.java | 20 +++++++++---- .../domain/VerificationRequest.java | 3 +- .../verification/dto/VerificationFormDto.java | 7 ++--- .../service/VerificationService.java | 30 ++++++++++--------- 6 files changed, 43 insertions(+), 29 deletions(-) diff --git a/src/main/java/com/example/petree/domain/matching/dto/MatchingFormDto.java b/src/main/java/com/example/petree/domain/matching/dto/MatchingFormDto.java index c7a5d0a..587d985 100644 --- a/src/main/java/com/example/petree/domain/matching/dto/MatchingFormDto.java +++ b/src/main/java/com/example/petree/domain/matching/dto/MatchingFormDto.java @@ -9,6 +9,7 @@ import org.springframework.web.multipart.MultipartFile; import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; import javax.validation.constraints.Size; import java.util.List; @@ -27,18 +28,21 @@ public class MatchingFormDto { @Schema(description = "브리더 식별자 id", example = "1") - @NotBlank(message = "브리더 정보는 필수 입력 값입니다.") + @NotNull(message = "브리더 정보는 필수 입력 값입니다.") private Long breederId; - @NotBlank(message = "강아지 정보는 필수 입력 값입니다.") + + @NotNull(message = "강아지 정보는 필수 입력 값입니다.") @Schema(description = "강아지 식별자 id", example = "1") private Long dogId; + @NotBlank(message = "문항1은 필수 입력 값입니다.") @Schema(description = "문항 1", example = "잘 키우겠습니다 ~") @Size(max = 2000, message = "문항1의 최대 글자수는 2000자입니다.") private String pledgeContent1; + @NotBlank(message = "문항2는 필수 입력 값입니다.") @Schema(description = "문항 2", example = "잘 키우겠습니다 ~") - @Size(max = 2000, message = "문항1의 최대 글자수는 2000자입니다.") + @Size(max = 2000, message = "문항2의 최대 글자수는 2000자입니다.") private String pledgeContent2; } diff --git a/src/main/java/com/example/petree/domain/member/repository/AdminRepository.java b/src/main/java/com/example/petree/domain/member/repository/AdminRepository.java index fd5e6f3..2a92e3e 100644 --- a/src/main/java/com/example/petree/domain/member/repository/AdminRepository.java +++ b/src/main/java/com/example/petree/domain/member/repository/AdminRepository.java @@ -1,9 +1,11 @@ package com.example.petree.domain.member.repository; import com.example.petree.domain.member.domain.Admin; +import com.example.petree.domain.member.domain.Role; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; @Repository public interface AdminRepository extends JpaRepository { + Admin findByRole(Role role); } diff --git a/src/main/java/com/example/petree/domain/verification/controller/VerificationController.java b/src/main/java/com/example/petree/domain/verification/controller/VerificationController.java index ce0fced..a3db003 100644 --- a/src/main/java/com/example/petree/domain/verification/controller/VerificationController.java +++ b/src/main/java/com/example/petree/domain/verification/controller/VerificationController.java @@ -3,7 +3,11 @@ import com.example.petree.domain.breeder.domain.Breeder; import com.example.petree.domain.breeder.repository.BreederRepository; +import com.example.petree.domain.member.domain.Admin; import com.example.petree.domain.member.domain.Member; + +import com.example.petree.domain.member.domain.Role; +import com.example.petree.domain.member.repository.AdminRepository; import com.example.petree.domain.member.repository.MemberRepository; import com.example.petree.domain.verification.domain.Certification; import com.example.petree.domain.verification.domain.Status; @@ -60,6 +64,7 @@ public class VerificationController { private final VerificationService verificationService; private final BreederRepository breederRepository; private final MemberRepository memberRepository; + private final AdminRepository adminRepository; private final Response response; @@ -84,10 +89,15 @@ public ResponseEntity addVerification( } Breeder breeder = breederRepository.findByEmail(principal.getName()).orElse(null); if(breeder != null) { - verificationService.addVerification(breeder, verificationFormDto); - return response.success(HttpStatus.OK, verificationFormDto); - }else { - return response.fail(HttpStatus.FORBIDDEN, Map.of("message", "브리더 회원이 아닙니다."));} - + Admin admin =adminRepository.findByRole(Role.ADMIN); + if (admin != null) { + verificationService.addVerification(breeder, verificationFormDto, admin); + return response.success(HttpStatus.OK, verificationFormDto); + } else { + return response.fail(HttpStatus.FORBIDDEN, Map.of("message", "관리자를 찾을 수 없습니다.")); + } + } else { + return response.fail(HttpStatus.FORBIDDEN, Map.of("message", "브리더 회원이 아닙니다.")); + } } } diff --git a/src/main/java/com/example/petree/domain/verification/domain/VerificationRequest.java b/src/main/java/com/example/petree/domain/verification/domain/VerificationRequest.java index 78304fc..5735cd5 100644 --- a/src/main/java/com/example/petree/domain/verification/domain/VerificationRequest.java +++ b/src/main/java/com/example/petree/domain/verification/domain/VerificationRequest.java @@ -50,10 +50,9 @@ public class VerificationRequest { @OneToMany(mappedBy = "verificationRequest",cascade = CascadeType.ALL) private List verificationFiles = new ArrayList<>(); - public VerificationRequest(LocalDate submitDate, Breeder breeder, Admin admin) { + public VerificationRequest(LocalDate submitDate, Breeder breeder) { this.submitDate= submitDate; this.breeder=breeder; - this.admin=admin; } public void addAttachedFile(AttachedFile attachedFile) { diff --git a/src/main/java/com/example/petree/domain/verification/dto/VerificationFormDto.java b/src/main/java/com/example/petree/domain/verification/dto/VerificationFormDto.java index 872f262..d31489c 100644 --- a/src/main/java/com/example/petree/domain/verification/dto/VerificationFormDto.java +++ b/src/main/java/com/example/petree/domain/verification/dto/VerificationFormDto.java @@ -23,15 +23,12 @@ public class VerificationFormDto { //@JsonProperty("breeder_id") private Long breederId; - @Schema(description = "관리자 식별자 id") - private Long adminId; - @Schema(description = "자격증 분류 선택 (반려동물종합관리사 OR 반려동물행동교정사)",example = "COMPREHENSIVE_PET_MANAGER") private Certification certification; - @Schema(description = "브리더 증명 파일 업로드 리스트") + @Schema(description = "브리더 증명 파일 업로드") @JsonSerialize(using = ToStringSerializer.class) - private List verificationFiles; + private MultipartFile verificationFiles; } diff --git a/src/main/java/com/example/petree/domain/verification/service/VerificationService.java b/src/main/java/com/example/petree/domain/verification/service/VerificationService.java index 0c6cfa0..69105ae 100644 --- a/src/main/java/com/example/petree/domain/verification/service/VerificationService.java +++ b/src/main/java/com/example/petree/domain/verification/service/VerificationService.java @@ -2,9 +2,11 @@ import com.example.petree.domain.member.domain.Admin; +import com.example.petree.domain.member.domain.Member; import com.example.petree.domain.member.repository.AdminRepository; import com.example.petree.domain.breeder.domain.Breeder; import com.example.petree.domain.breeder.repository.BreederRepository; +import com.example.petree.domain.member.repository.MemberRepository; import com.example.petree.domain.verification.domain.*; import com.example.petree.domain.verification.dto.VerificationFormDto; import com.example.petree.domain.verification.dto.VerificationListDto; @@ -59,7 +61,7 @@ public class VerificationService { private final VerificationRequestRepository verificationRequestRepository; private final VerificationApprovalRepository verificationApprovalRepository; private RequestSpecification requestSpecification; - private final AdminRepository adminRepository; + private final MemberRepository memberRepository; private final BreederRepository breederRepository; private final S3Util s3Util; private final FileUtil fileUtil; @@ -76,25 +78,25 @@ public class VerificationService { */ // 브리더가 관리자에게 자료를 첨부하여 인증 요청을 보내는 메소드 @Transactional - public void addVerification(Breeder breeder, VerificationFormDto verificationFormDto) { - Admin admin = adminRepository.findById(verificationFormDto.getAdminId()) - .orElseThrow(() -> new IllegalArgumentException("관리자에게 요청을 보낼 수 없습니다.")); + public void addVerification(Breeder breeder, VerificationFormDto verificationFormDto, Admin admin) { + // 새로운 요청을 생성한다. - VerificationRequest verificationRequest = new VerificationRequest(LocalDate.now(), breeder, admin); + VerificationRequest verificationRequest = new VerificationRequest(LocalDate.now(), breeder); // 처리 상태는 Watting으로 자동으로 저장한다. verificationRequest.setStatus(Status.WAITING); // 파일을 여러 개 첨부한다 - for (MultipartFile multipartFile : verificationFormDto.getVerificationFiles()) { - String originalName = multipartFile.getOriginalFilename(); - String filename = UUID.randomUUID().toString() + "." + fileUtil.extractExt(originalName); - String res = s3Util.upload(multipartFile, "verification-file", filename); - AttachedFile verificationFiles = new AttachedFile(originalName, filename, res, verificationRequest); - verificationRequest.addAttachedFile(verificationFiles); - verificationRequest.setCertification(verificationFormDto.getCertification()); - } - + MultipartFile multipartFile = verificationFormDto.getVerificationFiles(); + String originalName = multipartFile.getOriginalFilename(); + String filename = UUID.randomUUID().toString() + "." + fileUtil.extractExt(originalName); + String res = s3Util.upload(multipartFile, "verification-file", filename); + AttachedFile verificationFiles = new AttachedFile(originalName, filename, res, verificationRequest); + verificationRequest.addAttachedFile(verificationFiles); + verificationRequest.setCertification(verificationFormDto.getCertification()); + + // 관리자를 할당합니다. + verificationRequest.setAdmin(admin); verificationRequestRepository.save(verificationRequest); }