From 8b13a4abff61e615b3c7d0a092fb89867b9dd6cf Mon Sep 17 00:00:00 2001 From: KimChanJin97 Date: Mon, 6 May 2024 15:19:19 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EC=9E=90=EA=B8=B0=EC=86=8C=EA=B0=9C?= =?UTF-8?q?=EC=84=9C=20=EC=9D=B4=EB=AF=B8=EC=A7=80=20=EC=97=85=EB=A1=9C?= =?UTF-8?q?=EB=93=9C=ED=95=98=EC=A7=80=20=EC=95=8A=EC=9C=BC=EB=A9=B4=20?= =?UTF-8?q?=EB=B9=88=EB=A6=AC=EC=8A=A4=ED=8A=B8=20=EB=B0=98=ED=99=98?= =?UTF-8?q?=ED=86=A0=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../facefriend/bucket/BucketService.java | 11 +++-- .../member/domain/resume/Resume.java | 4 -- .../domain/resume/ResumeRepository.java | 4 -- .../resume/controller/ResumeController.java | 8 ++-- .../resume/exception/ResumeExceptionType.java | 12 +++--- .../resume/service/ResumeService.java | 40 ++++++++++++++----- 6 files changed, 47 insertions(+), 32 deletions(-) delete mode 100644 src/main/java/capstone/facefriend/member/domain/resume/Resume.java delete mode 100644 src/main/java/capstone/facefriend/member/domain/resume/ResumeRepository.java diff --git a/src/main/java/capstone/facefriend/bucket/BucketService.java b/src/main/java/capstone/facefriend/bucket/BucketService.java index 8e19088331..46a5d73303 100644 --- a/src/main/java/capstone/facefriend/bucket/BucketService.java +++ b/src/main/java/capstone/facefriend/bucket/BucketService.java @@ -1,14 +1,11 @@ package capstone.facefriend.bucket; -import capstone.facefriend.member.domain.faceInfo.FaceInfo; -import capstone.facefriend.member.domain.faceInfo.FaceInfoRepository; import capstone.facefriend.member.domain.member.Member; import capstone.facefriend.member.domain.member.MemberRepository; import capstone.facefriend.member.exception.member.MemberException; import capstone.facefriend.member.exception.member.MemberExceptionType; import capstone.facefriend.member.multipartFile.ByteArrayMultipartFile; -import capstone.facefriend.member.service.dto.faceInfo.FaceInfoResponse; import capstone.facefriend.resume.domain.Resume; import com.amazonaws.services.s3.AmazonS3; import com.amazonaws.services.s3.model.CannedAccessControlList; @@ -127,14 +124,20 @@ public String deleteOriginAndGenerated( } - // Resume : images 업로드 public List uploadResumeImages( List images ) throws IOException { + List resumeImageS3urls = new ArrayList<>(); for (MultipartFile image : images) { + + log.info("size = {}", image.getSize()); + if (image.isEmpty() || image.getSize() == 0) { + return List.of(); + } + ObjectMetadata metadata = new ObjectMetadata(); metadata.setContentLength(image.getInputStream().available()); metadata.setContentType(image.getContentType()); diff --git a/src/main/java/capstone/facefriend/member/domain/resume/Resume.java b/src/main/java/capstone/facefriend/member/domain/resume/Resume.java deleted file mode 100644 index 20a4487d75..0000000000 --- a/src/main/java/capstone/facefriend/member/domain/resume/Resume.java +++ /dev/null @@ -1,4 +0,0 @@ -package capstone.facefriend.member.domain.resume; - -public class Resume { -} diff --git a/src/main/java/capstone/facefriend/member/domain/resume/ResumeRepository.java b/src/main/java/capstone/facefriend/member/domain/resume/ResumeRepository.java deleted file mode 100644 index 74768626ee..0000000000 --- a/src/main/java/capstone/facefriend/member/domain/resume/ResumeRepository.java +++ /dev/null @@ -1,4 +0,0 @@ -package capstone.facefriend.member.domain.resume; - -public interface ResumeRepository { -} diff --git a/src/main/java/capstone/facefriend/resume/controller/ResumeController.java b/src/main/java/capstone/facefriend/resume/controller/ResumeController.java index feb6ebd870..d821e753bc 100644 --- a/src/main/java/capstone/facefriend/resume/controller/ResumeController.java +++ b/src/main/java/capstone/facefriend/resume/controller/ResumeController.java @@ -24,12 +24,12 @@ public class ResumeController { // 정적 쿼리 @PostMapping("/my-resume") - public ResponseEntity postResume( + public ResponseEntity postMyResume( @AuthMember Long memberId, @RequestPart("images") List images, @RequestPart("request") ResumePostRequest request ) throws IOException { - return ResponseEntity.ok(resumeService.postResume(memberId, images, request)); + return ResponseEntity.ok(resumeService.postMyResume(memberId, images, request)); } @GetMapping("/resume") @@ -53,14 +53,14 @@ public ResponseEntity putMyResume( @RequestPart("images") List images, @RequestPart("request") ResumePutRequest request ) throws IOException { - return ResponseEntity.ok(resumeService.putResume(memberId, images, request)); + return ResponseEntity.ok(resumeService.putMyResume(memberId, images, request)); } @DeleteMapping("/my-resume") public ResponseEntity deleteMyResume( @AuthMember Long memberId ) { - return ResponseEntity.ok(resumeService.deleteResume(memberId)); + return ResponseEntity.ok(resumeService.deleteMyResume(memberId)); } // 동적 쿼리 diff --git a/src/main/java/capstone/facefriend/resume/exception/ResumeExceptionType.java b/src/main/java/capstone/facefriend/resume/exception/ResumeExceptionType.java index 67b2183d6c..c5f538e094 100644 --- a/src/main/java/capstone/facefriend/resume/exception/ResumeExceptionType.java +++ b/src/main/java/capstone/facefriend/resume/exception/ResumeExceptionType.java @@ -5,11 +5,13 @@ public enum ResumeExceptionType implements ExceptionType { - NO_RESUME(Status.NOT_FOUND, 7001, "자기소개서가 없습니다!"), - ALREADY_HAS_RESUME(Status.BAD_REQUEST, 7002, "자기소개서는 1인당 1개만 생성할 수 있습니다!"), - UNAUTHORIZED(Status.UNAUTHORIZED, 7003, "나의 자기소개서가 아닙니다!"), - FAIL_TO_DELETE(Status.BAD_REQUEST, 7004, "자기소개서 삭제 실패"), - AT_LEAST_ONE_IMAGE(Status.BAD_REQUEST, 7005, "최소한 1개 이상의 이미지를 업로드해야 합니다!") + NO_RESUME(Status.NOT_FOUND, 7001, "자기소개서가 없습니다!"), // 404 + ALREADY_HAS_RESUME(Status.BAD_REQUEST, 7002, "자기소개서는 1인당 1개만 생성할 수 있습니다!"), // 400 + UNAUTHORIZED(Status.UNAUTHORIZED, 7003, "나의 자기소개서가 아닙니다!"), // 401 + FAIL_TO_DELETE(Status.BAD_REQUEST, 7004, "자기소개서 삭제 실패"), // 400 + MUST_UPLOAD_ONE_IMAGE(Status.BAD_REQUEST, 7005, "최소한 1개 이상의 이미지를 업로드해야 합니다!"), // 400 + MUST_SELECT_ONE_CATEGORY(Status.BAD_REQUEST, 7006, "최소한 1개 이상의 카테고리를 선택해야 합니다!"), + MUST_FILL_CONTENT(Status.BAD_REQUEST, 7007, "내용을 작성해야 합니다!") ; private final Status status; diff --git a/src/main/java/capstone/facefriend/resume/service/ResumeService.java b/src/main/java/capstone/facefriend/resume/service/ResumeService.java index f0f32f1f87..ecc2c5b4d6 100644 --- a/src/main/java/capstone/facefriend/resume/service/ResumeService.java +++ b/src/main/java/capstone/facefriend/resume/service/ResumeService.java @@ -37,20 +37,15 @@ public class ResumeService { private static final String DELETE_SUCCESS_MESSAGE = "자기소개서 삭제 완료!"; // 정적 쿼리 - public ResumePostPutResponse postResume( + public ResumePostPutResponse postMyResume( Long memberId, List images, ResumePostRequest request ) throws IOException { - if (images.size() == 0) { - throw new ResumeException(AT_LEAST_ONE_IMAGE); - } - - Member member = findMemberById(memberId); - if (resumeRepository.findResumeByMember(member).isPresent()) { - throw new ResumeException(ALREADY_HAS_RESUME); - } + validateCategories(request.categories()); + validateContent(request.content()); + Member member = validateMemberHasResume(memberId); List resumeImagesS3url = bucketService.uploadResumeImages(images); @@ -119,12 +114,15 @@ public ResumeGetResponse getMyResume( } @Transactional - public ResumePostPutResponse putResume( + public ResumePostPutResponse putMyResume( Long memberId, List images, ResumePutRequest request ) throws IOException { + validateCategories(request.categories()); + validateContent(request.content()); + Member me = findMemberById(memberId); Resume mine = findResumeByMember(me); // 영속 상태 @@ -147,7 +145,7 @@ public ResumePostPutResponse putResume( } @Transactional - public ResumeDeleteResponse deleteResume( + public ResumeDeleteResponse deleteMyResume( Long memberId ) { Member me = findMemberById(memberId); @@ -178,4 +176,24 @@ private Resume findResumeByMember(Member member) { return resumeRepository.findResumeByMember(member) .orElseThrow(() -> new ResumeException(NO_RESUME)); } + + private void validateContent(String content) { + if (content.trim().length() == 0 || content == null || content.isEmpty()) { + throw new ResumeException(MUST_FILL_CONTENT); + } + } + + private void validateCategories(List categories) { + if (categories.size() == 0 || categories == null || categories.isEmpty()) { + throw new ResumeException(MUST_SELECT_ONE_CATEGORY); + } + } + + private Member validateMemberHasResume(Long memberId){ + Member member = findMemberById(memberId); + if (resumeRepository.findResumeByMember(member).isPresent()) { + throw new ResumeException(ALREADY_HAS_RESUME); + } + return member; + } }