-
Notifications
You must be signed in to change notification settings - Fork 1
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
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
7938ff2
:sparkles: Feat: NickName Feign Client 세팅
swa07016 20d4dea
:sparkles: Feat: 애플로그인 랜덤 닉네임 세팅
swa07016 ad4bad9
:sparkles: Feat: 닉네임 생성 관련 상수 분리
swa07016 db5fdf6
:recycle: Refactor: 클라이언트 코드가 랜덤 닉네임 생성에 관여하지 않도록 Adapter 제공
swa07016 3d625cb
:white_check_mark: Test: NickNameGenerator 테스트 코드 작성
swa07016 5ed6b66
:sparkles: Feat: 기본 닉네임 세팅 & 응답 words 기본 빈 리스트 할당
swa07016 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
...efing-Common/src/main/java/com/example/briefingcommon/common/constant/BriefingStatic.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
51 changes: 51 additions & 0 deletions
51
...main/java/com/example/briefinginfra/feign/nickname/hwanmoo/adapter/NickNameGenerator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
return ""; | ||
} | ||
} | ||
|
17 changes: 17 additions & 0 deletions
17
...src/main/java/com/example/briefinginfra/feign/nickname/hwanmoo/client/NickNameClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
13 changes: 13 additions & 0 deletions
13
...Infra/src/main/java/com/example/briefinginfra/feign/nickname/hwanmoo/dto/NickNameRes.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.example.briefinginfra.feign.nickname.hwanmoo.dto; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
import java.util.List; | ||
|
||
@Getter | ||
@Setter | ||
public class NickNameRes { | ||
private List<String> words; | ||
private String seed; | ||
} |
20 changes: 20 additions & 0 deletions
20
core/Briefing-Infra/src/test/java/com/example/briefinginfra/config/TestConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.example.briefinginfra.config; | ||
|
||
import com.example.briefinginfra.feign.nickname.hwanmoo.adapter.NickNameGenerator; | ||
import com.example.briefinginfra.feign.nickname.hwanmoo.client.NickNameClient; | ||
import org.mockito.Mockito; | ||
import org.springframework.boot.test.context.TestConfiguration; | ||
import org.springframework.context.annotation.Bean; | ||
|
||
@TestConfiguration | ||
public class TestConfig { | ||
@Bean | ||
public NickNameClient nickNameClient() { | ||
return Mockito.mock(NickNameClient.class); | ||
} | ||
|
||
@Bean | ||
public NickNameGenerator nickNameGenerator(NickNameClient nickNameClient) { | ||
return new NickNameGenerator(nickNameClient); | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
.../java/com/example/briefinginfra/feign/nickname/hwanmoo/adapter/NickNameGeneratorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.example.briefinginfra.feign.nickname.hwanmoo.adapter; | ||
|
||
import com.example.briefinginfra.config.TestConfig; | ||
import com.example.briefinginfra.feign.nickname.hwanmoo.client.NickNameClient; | ||
import com.example.briefinginfra.feign.nickname.hwanmoo.dto.NickNameRes; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.boot.test.mock.mockito.MockBean; | ||
import org.springframework.test.context.ActiveProfiles; | ||
import org.springframework.test.context.ContextConfiguration; | ||
import org.springframework.test.context.junit.jupiter.SpringExtension; | ||
|
||
import java.util.Arrays; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.mockito.Mockito.when; | ||
|
||
@ExtendWith(SpringExtension.class) | ||
@ContextConfiguration(classes = TestConfig.class) // 테스트 설정 클래스 지정 | ||
class NickNameGeneratorTest { | ||
@Autowired | ||
private NickNameGenerator nickNameGenerator; | ||
|
||
@MockBean | ||
private NickNameClient nickNameClient; | ||
|
||
@Test | ||
@DisplayName("[NickNameGenerator] 랜덤 닉네임 생성") | ||
void 랜덤_닉네임_생성() throws Exception { | ||
// given | ||
NickNameRes mockResponse = new NickNameRes(); | ||
mockResponse.setWords(Arrays.asList("하품하는 프로도")); | ||
when(nickNameClient.getNickName("json", 1, 8)).thenReturn(mockResponse); | ||
|
||
// when | ||
String nickName = nickNameGenerator.getOneRandomNickName(); | ||
|
||
// then | ||
assertThat(nickName).isNotNull(); | ||
assertThat(nickName).isEqualTo("하품하는 프로도"); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
앞선 리뷰와 동일한데, nickNameWords.stream().findFirst();를 사용하는 방식에 대해서는 어떻게 생각하시나요?
빈 리스트의 경우 ""를 반환할지 아니면 기본 닉네임을 반환할지도 고민이 되네요