-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
feat: 기본 닉네임 정책 추가
- Loading branch information
1 parent
ecb4a9e
commit 2df37cd
Showing
10 changed files
with
122 additions
and
18 deletions.
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
24 changes: 24 additions & 0 deletions
24
backend/src/main/java/com/festago/auth/domain/UserInfoMemberMapper.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,24 @@ | ||
package com.festago.auth.domain; | ||
|
||
import com.festago.member.domain.DefaultNicknamePolicy; | ||
import com.festago.member.domain.Member; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.util.StringUtils; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class UserInfoMemberMapper { | ||
|
||
private final DefaultNicknamePolicy defaultNicknamePolicy; | ||
|
||
public Member toMember(UserInfo userInfo) { | ||
String nickname = userInfo.nickname(); | ||
return new Member( | ||
userInfo.socialId(), | ||
userInfo.socialType(), | ||
StringUtils.hasText(nickname) ? nickname : defaultNicknamePolicy.generate(), | ||
userInfo.profileImage() | ||
); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
backend/src/main/java/com/festago/member/config/DefaultNicknamePolicyConfig.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,27 @@ | ||
package com.festago.member.config; | ||
|
||
import com.festago.member.domain.DefaultNicknamePolicy; | ||
import com.festago.member.infrastructure.DefaultNicknamePolicyImpl; | ||
import java.util.List; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
public class DefaultNicknamePolicyConfig { | ||
|
||
@Bean | ||
public DefaultNicknamePolicy defaultNicknamePolicy() { | ||
List<String> adjectives = List.of( | ||
"츄러스를 먹는", "노래 부르는", "때창하는", "응원하는", | ||
"응원봉을 든", "타코야끼를 먹는", "공연에 심취한", "신나는", | ||
"춤추는", "행복한", "즐거운", "신나는", "흥겨운" | ||
); | ||
List<String> nouns = List.of( | ||
"다람쥐", "토끼", "고양이", "펭귄", | ||
"캥거루", "사슴", "미어캣", "호랑이", | ||
"여우", "판다", "고슴도치", "토끼", | ||
"햄스터", "얼룩말", "너구리", "치타" | ||
); | ||
return new DefaultNicknamePolicyImpl(adjectives, nouns); | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
backend/src/main/java/com/festago/member/domain/DefaultNicknamePolicy.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,6 @@ | ||
package com.festago.member.domain; | ||
|
||
public interface DefaultNicknamePolicy { | ||
|
||
String generate(); | ||
} |
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
22 changes: 22 additions & 0 deletions
22
backend/src/main/java/com/festago/member/infrastructure/DefaultNicknamePolicyImpl.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,22 @@ | ||
package com.festago.member.infrastructure; | ||
|
||
import com.festago.member.domain.DefaultNicknamePolicy; | ||
import java.util.List; | ||
import java.util.Random; | ||
import java.util.concurrent.ThreadLocalRandom; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@RequiredArgsConstructor | ||
public class DefaultNicknamePolicyImpl implements DefaultNicknamePolicy { | ||
|
||
private final List<String> adjectives; | ||
private final List<String> nouns; | ||
|
||
@Override | ||
public String generate() { | ||
Random random = ThreadLocalRandom.current(); | ||
String adjective = adjectives.get(random.nextInt(adjectives.size())); | ||
String noun = nouns.get(random.nextInt(nouns.size())); | ||
return adjective + " " + noun; | ||
} | ||
} |
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
29 changes: 29 additions & 0 deletions
29
backend/src/test/java/com/festago/member/infrastructure/DefaultNicknamePolicyImplTest.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,29 @@ | ||
package com.festago.member.infrastructure; | ||
|
||
import static org.assertj.core.api.Assertions.*; | ||
|
||
import com.festago.member.domain.DefaultNicknamePolicy; | ||
import java.util.List; | ||
import org.junit.jupiter.api.DisplayNameGeneration; | ||
import org.junit.jupiter.api.DisplayNameGenerator; | ||
import org.junit.jupiter.api.Test; | ||
|
||
@DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) | ||
@SuppressWarnings("NonAsciiCharacters") | ||
class DefaultNicknamePolicyImplTest { | ||
|
||
@Test | ||
void 형용사와_명사가_합쳐진_닉네임이_반환된다() { | ||
// given | ||
DefaultNicknamePolicy defaultNicknamePolicy = new DefaultNicknamePolicyImpl( | ||
List.of("춤추는"), | ||
List.of("다람쥐") | ||
); | ||
|
||
// when | ||
String nickname = defaultNicknamePolicy.generate(); | ||
|
||
// then | ||
assertThat(nickname).isEqualTo("춤추는 다람쥐"); | ||
} | ||
} |