From 02af8cc66490a3354768f5d1ce8695e1d54c51a1 Mon Sep 17 00:00:00 2001 From: Lee-DoHa Date: Wed, 7 Dec 2022 13:19:09 +0900 Subject: [PATCH] Update MemberService.java --- .../member/service/MemberService.java | 26 ++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/project/csletter/member/service/MemberService.java b/src/main/java/com/project/csletter/member/service/MemberService.java index df5c7df..cf7c0ca 100644 --- a/src/main/java/com/project/csletter/member/service/MemberService.java +++ b/src/main/java/com/project/csletter/member/service/MemberService.java @@ -2,6 +2,7 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; +import com.project.csletter.global.service.S3Uploader; import com.project.csletter.global.utils.SecurityUtil; import com.project.csletter.jwt.JwtService; import com.project.csletter.jwt.TokenRequestDto; @@ -25,6 +26,7 @@ import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; import org.springframework.web.client.RestTemplate; +import org.springframework.web.multipart.MultipartFile; import java.util.List; import java.util.Random; @@ -39,6 +41,7 @@ public class MemberService { private final MessageRepository messageRepository; private final MarkingRepository markingRepository; private final JwtService jwtService; + private final S3Uploader s3Uploader; @Value("${spring.security.oauth2.client.registration.kakao.client-id}") String client_id; @@ -169,7 +172,9 @@ public MemberResponse getMyInfo() { .solving(0L) .build(); - + if(!member.getNickname().isEmpty()) { + memberResponse.setKakaoNickname(member.getNickname()); + } List messages = messageRepository.findAllByToMemberToken(member.getMemberToken()); @@ -194,8 +199,8 @@ public MemberProfile getMemberInfo(String memberToken) { MemberProfile memberProfile = MemberProfile.builder() .userCode(member.getUserCode()) .kakaoProfileImg(member.getKakaoProfileImg()) - .kakaoNickname(member.getKakaoNickname()) .kakaoEmail(member.getKakaoEmail()) + .kakaoNickname(member.getKakaoNickname()) .userRole(member.getUserRole()) .memberToken(member.getMemberToken()) .countMessage(messageRepository.countAllByToMemberToken(member.getMemberToken())) @@ -203,6 +208,9 @@ public MemberProfile getMemberInfo(String memberToken) { .notRead(messageRepository.countAllByToMemberTokenAndIsReadFalse(member.getMemberToken())) .solving(0L) .build(); + if(!member.getNickname().isEmpty()) { + memberProfile.setKakaoNickname(member.getNickname()); + } try { String name = SecurityUtil.getLoginUsername(); @@ -230,7 +238,10 @@ public String getMemberName(String memberToken) { Member member = memberRepository.findByMemberToken(memberToken) .orElseThrow(); - return member.getKakaoNickname(); + if(member.getNickname().isEmpty()) { + return member.getKakaoNickname(); + } + return member.getNickname(); } @@ -271,4 +282,13 @@ public String createMemberToken() { } return newWord.toString(); } + + @Transactional + public void updateMember(MemberUpdate memberUpdate, MultipartFile multipartFile) { + Member member = memberRepository.findByKakaoNickname((SecurityUtil.getLoginUsername())).orElseThrow(); + member.updateNickname(memberUpdate.getNickname()); + if(multipartFile != null) { + member.addKakaoProfileImage(s3Uploader.getThumbnailPath(s3Uploader.uploadImage(multipartFile))); + } + } }