Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/177 : 애플로그인 사용자명 랜덤 세팅 #198

Merged
merged 6 commits into from
Mar 12, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,13 @@ public static Member toMember(GoogleUserInfo googleUserInfo) {
.build();
}

public static Member toMember(String appleSocialId) {
public static Member toMember(String appleSocialId, String nickName) {
return Member.builder()
// .profileImgUrl(googleUserInfo.getPicture())
// .nickName(googleUserInfo.getName())
.socialId(appleSocialId)
.socialType(SocialType.APPLE)
.nickName(nickName)
.role(MemberRole.ROLE_USER)
.status(MemberStatus.ACTIVE)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
import java.security.PublicKey;
import java.security.spec.RSAPublicKeySpec;
import java.util.Base64;
import java.util.List;
import java.util.Optional;

import com.example.briefingapi.member.business.MemberConverter;
import com.example.briefingcommon.common.constant.BriefingStatic;
import com.example.briefingcommon.domain.repository.FcmTokenRepository;
import com.example.briefingcommon.domain.repository.member.MemberRepository;
import com.example.briefingapi.member.presentation.dto.MemberRequest;
Expand All @@ -16,28 +18,31 @@
import com.example.briefingcommon.entity.FcmToken;
import com.example.briefingcommon.entity.Member;
import com.example.briefingcommon.entity.enums.SocialType;
import com.example.briefinginfra.feign.nickname.hwanmoo.client.NickNameClient;
import com.example.briefinginfra.feign.oauth.apple.client.AppleOauth2Client;
import com.example.briefinginfra.feign.oauth.apple.dto.ApplePublicKey;
import com.example.briefinginfra.feign.oauth.apple.dto.ApplePublicKeyList;
import com.example.briefinginfra.feign.oauth.google.client.GoogleOauth2Client;

import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;


import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import lombok.RequiredArgsConstructor;

import static com.example.briefingcommon.common.constant.BriefingStatic.*;

@Service
@RequiredArgsConstructor
public class MemberCommandService {

private final MemberRepository memberRepository;
private final AppleOauth2Client appleOauth2Client;
private final NickNameClient nickNameClient;

private final FcmTokenRepository fcmTokenRepository;

Expand Down Expand Up @@ -87,8 +92,12 @@ private Member loginWithApple(MemberRequest.LoginDTO request) {
Optional<Member> foundMember =
memberRepository.findBySocialIdAndSocialType(appleSocialId, SocialType.APPLE);

String nickName = "";
List<String> nickNameWords = nickNameClient.getNickName(NICK_NAME_FORMAT, NICK_NAME_COUNT, NICK_NAME_MAX_LENGTH).getWords();
if(!nickNameWords.isEmpty()) nickName = nickNameWords.get(0);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

닉네임이 빈 리스트인 경우는 어떻게 될까요?
nickNameWords.stream().findFirst();를 이용하여 null인 경우에 대해 예외처리를 안해도 될지 궁금합니다!


return foundMember.isEmpty()
? memberRepository.save(MemberConverter.toMember(appleSocialId))
? memberRepository.save(MemberConverter.toMember(appleSocialId, nickName))
: foundMember.get();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.example.briefingcommon.common.constant;

public class BriefingStatic {
public static final String NICK_NAME_FORMAT = "json";
public static final int NICK_NAME_COUNT = 1;
public static final int NICK_NAME_MAX_LENGTH = 8;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.example.briefinginfra.feign.nickname.hwanmoo.client;

import com.example.briefinginfra.feign.nickname.hwanmoo.dto.NickNameRes;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

@FeignClient(
name = "nickNameClient",
url = "https://nickname.hwanmoo.kr"
)
@Component
public interface NickNameClient {
@GetMapping(value = "/")
NickNameRes getNickName(@RequestParam(defaultValue = "json") String format, @RequestParam(defaultValue = "1") int count, @RequestParam(defaultValue = "8") int max_length);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.example.briefinginfra.feign.nickname.hwanmoo.dto;

import lombok.Getter;

import java.util.List;

@Getter
public class NickNameRes {
private List<String> words;
private String seed;
}