Skip to content

Commit

Permalink
Merge pull request #179 from BETTER-iTER/feature/178
Browse files Browse the repository at this point in the history
[Feature/178] 유저 프로필 수정 api null 분기 처리 및 이미지 url 문제 해결
  • Loading branch information
luke0408 authored Feb 26, 2024
2 parents fe19496 + 6c5fb38 commit c547db9
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ public ResponseDto<MypageResponse.PointDetailDto> getPointDetail() {
*/
@PutMapping("/profile")
public ResponseDto<Void> updateUserProfile(
@RequestPart(value = "files") MultipartFile image,
@Valid @RequestPart(value = "key") MypageRequest.UpdateProfileRequest request
@RequestPart(value = "files", required = false) MultipartFile image,
@Valid @RequestPart(value = "key", required = false) MypageRequest.UpdateProfileRequest request
) {
Users user = mypageService.getCurrentUser();
mypageService.updateUserProfile(user, request, image);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,24 +119,22 @@ public Page<Review> getUserReviewList(Long userId, int page) {

public void updateUserProfile(Users user, MypageRequest.UpdateProfileRequest request, MultipartFile image) {
// 1. 프로필 이미지 업로드
String profileImageUrl = this.uploadProfileImage(user, image);
String profileImageUrl = uploadProfileImage(user, image);

// 2. 프로필 정보 수정
UsersDetail detail = user.getUsersDetail();
detail.updateProfile(request, profileImageUrl);
detail.updateProfile(request.getNickname(), request.getJob(), profileImageUrl);
userService.updateUserDetail(detail);
}

private String uploadProfileImage(Users user, MultipartFile image) {
this.checkUploadProfileImageRequestValidation(image);
if (!isImageRequestValidation(image)) return null;
return s3Service.uploadImage(image, user);
}

private void checkUploadProfileImageRequestValidation(MultipartFile image) {
if(image == null || image.isEmpty()) {
throw new MypageHandler(_IMAGE_FILE_UPLOAD_REQUEST_IS_NOT_VALID);
}
}
private boolean isImageRequestValidation(MultipartFile image) {
return image != null && !image.isEmpty();
}

public void updateUserCategory(Users user, MypageRequest.UpdateCategoryRequest request) {
userService.updateUserCategory(user, request.getCategories());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ private UsersDetail(String nickName, Job job, String profileImage,
this.quizCount = quizCount;
}

public void updateProfile(MypageRequest.UpdateProfileRequest request, String profileImageUrl) {
this.nickName = request.getNickname();
this.job = request.getJob();
this.profileImage = profileImageUrl;
public void updateProfile(String nickName, Job job, String profileImageUrl) {
this.nickName = nickName == null? this.nickName : nickName;
this.job = job == null? this.job : job;
this.profileImage = profileImageUrl == null? this.profileImage : profileImageUrl;
}
}
3 changes: 2 additions & 1 deletion src/main/java/com/example/betteriter/infra/s3/S3Service.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import static com.example.betteriter.global.common.code.status.ErrorStatus._IMAGE_FILE_UPLOAD_FAILED;

import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
import com.amazonaws.services.s3.model.ObjectMetadata;
import com.amazonaws.services.s3.model.PutObjectRequest;
import com.example.betteriter.fo_domain.review.domain.Review;
Expand Down Expand Up @@ -115,6 +116,6 @@ private void validateImageFileExists(MultipartFile multipartFile) {


private String getImageUrl(String key) {
return "https://" + bucketName + ".s3.amazonaws.com/" + key;
return s3Client.getUrl(bucketName, key).toString();
}
}

0 comments on commit c547db9

Please sign in to comment.