diff --git a/server/src/main/java/com/yogit/server/user/exception/NotFoundUserProfileImg.java b/server/src/main/java/com/yogit/server/user/exception/NotFoundUserProfileImg.java new file mode 100644 index 0000000..6076f92 --- /dev/null +++ b/server/src/main/java/com/yogit/server/user/exception/NotFoundUserProfileImg.java @@ -0,0 +1,10 @@ +package com.yogit.server.user.exception; + + +import static com.yogit.server.user.exception.UserExceptionList.NOT_FOUND_PROFILE_IMG; + +public class NotFoundUserProfileImg extends UserException{ + public NotFoundUserProfileImg(){ + super(NOT_FOUND_PROFILE_IMG.getCODE(), NOT_FOUND_PROFILE_IMG.getHTTPSTATUS(), NOT_FOUND_PROFILE_IMG.getMESSAGE()); + } +} diff --git a/server/src/main/java/com/yogit/server/user/exception/UserExceptionList.java b/server/src/main/java/com/yogit/server/user/exception/UserExceptionList.java index f17b24f..cf1b51e 100644 --- a/server/src/main/java/com/yogit/server/user/exception/UserExceptionList.java +++ b/server/src/main/java/com/yogit/server/user/exception/UserExceptionList.java @@ -12,7 +12,8 @@ public enum UserExceptionList { NOT_FOUND_ID("U0001", NOT_FOUND,"존재하지 않는 아이디입니다."), - DUPLICATE_LOGIN_ID("U0002", CONFLICT,"이미 존재하는 아이디입니다."); + DUPLICATE_LOGIN_ID("U0002", CONFLICT,"이미 존재하는 아이디입니다."), + NOT_FOUND_PROFILE_IMG("U0003", NOT_FOUND, "프로필 사진은 필수 값 입니다."); private final String CODE; private final HttpStatus HTTPSTATUS; diff --git a/server/src/main/java/com/yogit/server/user/service/UserServiceImpl.java b/server/src/main/java/com/yogit/server/user/service/UserServiceImpl.java index 205ded8..fe6fda2 100644 --- a/server/src/main/java/com/yogit/server/user/service/UserServiceImpl.java +++ b/server/src/main/java/com/yogit/server/user/service/UserServiceImpl.java @@ -12,6 +12,7 @@ import com.yogit.server.user.dto.response.UserProfileRes; import com.yogit.server.user.entity.*; import com.yogit.server.user.exception.NotFoundUserException; +import com.yogit.server.user.exception.NotFoundUserProfileImg; import com.yogit.server.user.exception.UserDuplicationLoginId; import com.yogit.server.user.repository.*; import lombok.RequiredArgsConstructor; @@ -107,17 +108,17 @@ public ApplicationResponse enterUserImage(CreateUserImageReq crea User user = userRepository.findById(createUserImageReq.getUserId()).orElseThrow(NotFoundUserException::new); UserImagesRes userImagesRes = new UserImagesRes(); - userImageRepository.deleteAllByUserId(user.getId()); + if(createUserImageReq.getProfileImage().isEmpty()) throw new NotFoundUserProfileImg(); // 메인 프로필 사진 업로드 - if (createUserImageReq.getProfileImage() != null){ - String mainImageUUid = awsS3Service.uploadImage(createUserImageReq.getProfileImage()); - user.changeMainImgUUid(mainImageUUid); - userImagesRes.setProfileImageUrl(awsS3Service.makeUrlOfFilename(mainImageUUid)); - } + String mainImageUUid = awsS3Service.uploadImage(createUserImageReq.getProfileImage()); + user.changeMainImgUUid(mainImageUUid); + userImagesRes.setProfileImageUrl(awsS3Service.makeUrlOfFilename(mainImageUUid)); // 나머지 사진 업로드 if(createUserImageReq.getImages() != null){ + userImageRepository.deleteAllByUserId(user.getId()); + List imageUUids = awsS3Service.uploadImages(createUserImageReq.getImages()); for(String i : imageUUids){ UserImage userImage = createUserImageReq.toEntityUserImage(user, i);