Skip to content

Commit

Permalink
Merge pull request #44 from kakao-tech-campus-2nd-step3/bug/43-member…
Browse files Browse the repository at this point in the history
…-edit

fix: 회원 정보 수정 API 에러 해결
  • Loading branch information
peeerr authored Oct 6, 2024
2 parents 98a1b79 + 769f951 commit 50dc391
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,10 @@ public ResponseEntity<SuccessResponse<Void>> deleteMember(@AuthenticationPrincip
}

private void validateProfileUpdate(MultipartFile profileImage, String nickname) {
if (profileImage == null && !StringUtils.hasText(nickname)) {
boolean isProfileImageEmpty = profileImage == null || profileImage.isEmpty();
boolean isNicknameEmpty = !StringUtils.hasText(nickname);

if (isProfileImageEmpty && isNicknameEmpty) {
throw new GlobalException(ErrorCode.INFO_REQUIRED);
}
}
Expand Down
10 changes: 8 additions & 2 deletions src/main/java/com/potatocake/everymoment/entity/Member.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.potatocake.everymoment.entity;

import static org.springframework.util.StringUtils.hasText;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
Expand Down Expand Up @@ -40,8 +42,12 @@ public class Member extends BaseTimeEntity {
private boolean deleted = false;

public void update(String nickname, String profileImageUrl) {
this.nickname = nickname;
this.profileImageUrl = profileImageUrl;
if (hasText(nickname)) {
this.nickname = nickname;
}
if (profileImageUrl != null) {
this.profileImageUrl = profileImageUrl;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,18 @@ public void updateMemberInfo(Long id, MultipartFile profileImage, String nicknam
Member member = memberRepository.findById(id)
.orElseThrow(() -> new GlobalException(ErrorCode.MEMBER_NOT_FOUND));

String profileImageUrl = s3FileUploader.uploadFile(profileImage);
String profileImageUrl = null;
if (profileImage != null && !profileImage.isEmpty()) {
profileImageUrl = s3FileUploader.uploadFile(profileImage);
}

member.update(nickname, profileImageUrl);
}

public void deleteMember(Long memberId) {
Member member = memberRepository.findById(memberId)
.orElseThrow(() -> new GlobalException(ErrorCode.MEMBER_NOT_FOUND));

memberRepository.delete(member);
}

Expand Down

0 comments on commit 50dc391

Please sign in to comment.