From 755c5c80b009ee405bd85ba4fa366fcd5b94ad34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B5=9C=ED=9C=98=EC=9A=A9?= <99064014+slimsha2dy@users.noreply.github.com> Date: Mon, 21 Oct 2024 13:16:12 +0900 Subject: [PATCH] =?UTF-8?q?[Fix]=20=ED=94=84=EB=A1=9C=ED=95=84=20=EC=82=AC?= =?UTF-8?q?=EC=A7=84=20=EB=B9=88=20=EA=B0=92=20=EC=98=88=EC=99=B8=EC=B2=98?= =?UTF-8?q?=EB=A6=AC=20=EC=82=AD=EC=A0=9C=20(#542)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/kr/touroot/member/domain/Member.java | 8 +++++++- .../member/dto/request/ProfileUpdateRequest.java | 3 ++- .../java/kr/touroot/member/service/MemberService.java | 10 ++++++---- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/backend/src/main/java/kr/touroot/member/domain/Member.java b/backend/src/main/java/kr/touroot/member/domain/Member.java index bef12987..7de4c5de 100644 --- a/backend/src/main/java/kr/touroot/member/domain/Member.java +++ b/backend/src/main/java/kr/touroot/member/domain/Member.java @@ -131,9 +131,15 @@ private void validateProfileImageUrlForm(String profileImageUrl) { } } + private void validateProfileImageUrlNotNull(String profileImageUrl) { + if (profileImageUrl == null) { + throw new BadRequestException("프로필 이미지는 비어 있을 수 없습니다"); + } + } + public void update(String nickname, String profileImageUrl) { validateNickname(nickname); - validateProfileImageUrl(profileImageUrl); + validateProfileImageUrlNotNull(profileImageUrl); this.nickname = nickname; this.profileImageUrl = profileImageUrl; } diff --git a/backend/src/main/java/kr/touroot/member/dto/request/ProfileUpdateRequest.java b/backend/src/main/java/kr/touroot/member/dto/request/ProfileUpdateRequest.java index fc998bb0..280bd4d8 100644 --- a/backend/src/main/java/kr/touroot/member/dto/request/ProfileUpdateRequest.java +++ b/backend/src/main/java/kr/touroot/member/dto/request/ProfileUpdateRequest.java @@ -2,13 +2,14 @@ import io.swagger.v3.oas.annotations.media.Schema; import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotNull; public record ProfileUpdateRequest( @Schema(description = "사용자 닉네임", example = "아기뚜리") @NotBlank(message = "닉네임은 비어있을 수 없습니다.") String nickname, @Schema(description = "사용자 프로필 사진 URL", example = "https://dev.touroot.kr/profile-image-ex.png") - @NotBlank(message = "프로필 사진 URL은 비어있을 수 없습니다.") + @NotNull(message = "프로필 사진 URL은 null 값일 수 없습니다.") String profileImageUrl ) { } diff --git a/backend/src/main/java/kr/touroot/member/service/MemberService.java b/backend/src/main/java/kr/touroot/member/service/MemberService.java index b3414dc2..b2e45530 100644 --- a/backend/src/main/java/kr/touroot/member/service/MemberService.java +++ b/backend/src/main/java/kr/touroot/member/service/MemberService.java @@ -58,14 +58,16 @@ private void validateNicknameDuplication(String nickname) { public ProfileResponse updateProfile(ProfileUpdateRequest request, MemberAuth memberAuth) { Member member = getMemberById(memberAuth.memberId()); String requestProfileImageUrl = request.profileImageUrl(); - if (!Objects.equals(request.profileImageUrl(), member.getProfileImageUrl())) { + if (isUpdatable(requestProfileImageUrl, member)) { requestProfileImageUrl = s3Provider.copyImageToPermanentStorage(request.profileImageUrl()); } member.update(request.nickname(), requestProfileImageUrl); -// Member member = getMemberById(memberAuth.memberId()); -// member.changeNickname(request.nickname()); - return ProfileResponse.from(member); } + + private boolean isUpdatable(String requestProfileImageUrl, Member member) { + return !requestProfileImageUrl.isEmpty() && !Objects.equals(requestProfileImageUrl, + member.getProfileImageUrl()); + } }