Skip to content

Commit

Permalink
Update MemberService.java
Browse files Browse the repository at this point in the history
  • Loading branch information
Lee-DoHa committed Dec 7, 2022
1 parent 39029f2 commit 02af8cc
Showing 1 changed file with 23 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -169,7 +172,9 @@ public MemberResponse getMyInfo() {
.solving(0L)
.build();


if(!member.getNickname().isEmpty()) {
memberResponse.setKakaoNickname(member.getNickname());
}

List<Message> messages = messageRepository.findAllByToMemberToken(member.getMemberToken());

Expand All @@ -194,15 +199,18 @@ 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()))
.correctMessage(0L)
.notRead(messageRepository.countAllByToMemberTokenAndIsReadFalse(member.getMemberToken()))
.solving(0L)
.build();
if(!member.getNickname().isEmpty()) {
memberProfile.setKakaoNickname(member.getNickname());
}

try {
String name = SecurityUtil.getLoginUsername();
Expand Down Expand Up @@ -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();
}


Expand Down Expand Up @@ -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)));
}
}
}

0 comments on commit 02af8cc

Please sign in to comment.