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 @@ -9,7 +9,6 @@
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 @@ -18,7 +17,7 @@
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.nickname.hwanmoo.adapter.NickNameGenerator;
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;
Expand All @@ -34,15 +33,13 @@
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 NickNameGenerator nickNameGenerator;

private final FcmTokenRepository fcmTokenRepository;

Expand Down Expand Up @@ -92,9 +89,7 @@ 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);
String nickName = nickNameGenerator.getOneRandomNickName();

return foundMember.isEmpty()
? memberRepository.save(MemberConverter.toMember(appleSocialId, nickName))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.example.briefinginfra.feign.nickname.hwanmoo.adapter;

import com.example.briefinginfra.feign.nickname.hwanmoo.client.NickNameClient;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import java.util.List;

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

@Component
@RequiredArgsConstructor
public class NickNameGenerator {
private final NickNameClient nickNameClient;

/**
* 기본 최대 길이를 사용하여 랜덤 닉네임을 생성하고 반환합니다.
* 이 메소드는 내부적으로 {@code getOneRandomNickNameWithDetails}를 호출합니다.
*
* @return 생성된 닉네임. 닉네임 생성에 실패한 경우 빈 문자열을 반환합니다.
*/
public String getOneRandomNickName() {
return getOneRandomNickNameWithDetails(NICK_NAME_MAX_LENGTH);
}

/**
* 사용자가 지정한 최대 길이를 사용하여 랜덤 닉네임을 생성하고 반환합니다.
* 이 메소드는 내부적으로 {@code getOneRandomNickNameWithDetails}를 호출합니다.
*
* @param maxLength 생성할 닉네임의 최대 길이
* @return 생성된 닉네임. 닉네임 생성에 실패한 경우 빈 문자열을 반환합니다.
*/
public String getOneRandomNickName(int maxLength) {
return getOneRandomNickNameWithDetails(maxLength);
}

/**
* 지정된 최대 길이를 사용하여 랜덤 닉네임을 생성하고, 생성된 목록에서 첫 번째 닉네임을 반환합니다.
* 이 메소드는 내부적으로 {@code NickNameClient}를 사용하여 닉네임을 요청합니다.
*
* @param maxLength 생성할 닉네임의 최대 길이
* @return 생성된 닉네임 중 첫 번째 닉네임. 닉네임 생성에 실패한 경우 빈 문자열을 반환합니다.
*/
private String getOneRandomNickNameWithDetails(int maxLength) {
List<String> nickNameWords = nickNameClient.getNickName(NICK_NAME_FORMAT, NICK_NAME_COUNT, maxLength).getWords();
if (!nickNameWords.isEmpty()) return nickNameWords.get(0);
Copy link
Member

@CYY1007 CYY1007 Mar 11, 2024

Choose a reason for hiding this comment

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

앞선 리뷰와 동일한데, nickNameWords.stream().findFirst();를 사용하는 방식에 대해서는 어떻게 생각하시나요?
빈 리스트의 경우 ""를 반환할지 아니면 기본 닉네임을 반환할지도 고민이 되네요

return "";
}
}