Skip to content

Commit

Permalink
Merge pull request #43 from kookmin-sw/feat/chat4
Browse files Browse the repository at this point in the history
feat: 자기소개서 이미지 업로드하지 않으면 빈리스트 반환토록 수정
  • Loading branch information
KimChanJin97 authored May 6, 2024
2 parents 287335f + 8b13a4a commit e66f27f
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 32 deletions.
11 changes: 7 additions & 4 deletions src/main/java/capstone/facefriend/bucket/BucketService.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -127,14 +124,20 @@ public String deleteOriginAndGenerated(
}



// Resume : images 업로드
public List<String> uploadResumeImages(
List<MultipartFile> images
) throws IOException {

List<String> 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());
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ public class ResumeController {

// 정적 쿼리
@PostMapping("/my-resume")
public ResponseEntity<ResumePostPutResponse> postResume(
public ResponseEntity<ResumePostPutResponse> postMyResume(
@AuthMember Long memberId,
@RequestPart("images") List<MultipartFile> 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")
Expand All @@ -53,14 +53,14 @@ public ResponseEntity<ResumePostPutResponse> putMyResume(
@RequestPart("images") List<MultipartFile> 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<ResumeDeleteResponse> deleteMyResume(
@AuthMember Long memberId
) {
return ResponseEntity.ok(resumeService.deleteResume(memberId));
return ResponseEntity.ok(resumeService.deleteMyResume(memberId));
}

// 동적 쿼리
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
40 changes: 29 additions & 11 deletions src/main/java/capstone/facefriend/resume/service/ResumeService.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,15 @@ public class ResumeService {
private static final String DELETE_SUCCESS_MESSAGE = "자기소개서 삭제 완료!";

// 정적 쿼리
public ResumePostPutResponse postResume(
public ResumePostPutResponse postMyResume(
Long memberId,
List<MultipartFile> 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<String> resumeImagesS3url = bucketService.uploadResumeImages(images);

Expand Down Expand Up @@ -119,12 +114,15 @@ public ResumeGetResponse getMyResume(
}

@Transactional
public ResumePostPutResponse putResume(
public ResumePostPutResponse putMyResume(
Long memberId,
List<MultipartFile> images,
ResumePutRequest request
) throws IOException {

validateCategories(request.categories());
validateContent(request.content());

Member me = findMemberById(memberId);
Resume mine = findResumeByMember(me); // 영속 상태

Expand All @@ -147,7 +145,7 @@ public ResumePostPutResponse putResume(
}

@Transactional
public ResumeDeleteResponse deleteResume(
public ResumeDeleteResponse deleteMyResume(
Long memberId
) {
Member me = findMemberById(memberId);
Expand Down Expand Up @@ -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<String> 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;
}
}

0 comments on commit e66f27f

Please sign in to comment.