Skip to content

Commit

Permalink
Merge pull request #51 from tukcomCD2024/ARCH-141-feat/Make_Random_Ni…
Browse files Browse the repository at this point in the history
…ckName

Arch 141 feat/make random nick name
  • Loading branch information
seokho-1116 authored Jan 20, 2024
2 parents 88eea0c + 6f83af2 commit 8848c84
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package site.timecapsulearchive.core.domain.auth.repository;

import java.util.Optional;
import java.util.concurrent.TimeUnit;
import lombok.RequiredArgsConstructor;
import org.springframework.data.redis.core.StringRedisTemplate;
Expand All @@ -18,7 +19,7 @@ public void save(final Long memberId, final String code) {
redisTemplate.opsForValue().set(PREFIX + memberId, code, MINUTE, TimeUnit.MINUTES);
}

public String get(final Long memberId) {
return redisTemplate.opsForValue().get(PREFIX + memberId);
public Optional<String> get(final Long memberId) {
return Optional.ofNullable(redisTemplate.opsForValue().get(PREFIX + memberId));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,8 @@ public TokenResponse getRandomNickname(
final String certificationNumber,
final String receiver
) {
String findCertificationNumber = messageAuthenticationCacheRepository.get(memberId);

if (isNull(findCertificationNumber)) {
throw new NotFoundCertificationNumberException();
}
String findCertificationNumber = messageAuthenticationCacheRepository.get(memberId)
.orElseThrow(NotFoundCertificationNumberException::new);

if (isNotMatch(certificationNumber, findCertificationNumber)) {
throw new NotMatchCertificationNumberException();
Expand All @@ -85,14 +82,11 @@ public TokenResponse getRandomNickname(
Member findMember = memberService.findMemberByMemberId(memberId);
findMember.updateVerification();
findMember.updatePhoneNumber(receiver);
findMember.updateNickName();

return tokenService.createNewToken(memberId);
}

private boolean isNull(String findCertificationNumber) {
return findCertificationNumber == null;
}

private boolean isNotMatch(String certificationNumber, String findCertificationNumber) {
return !certificationNumber.equals(findCertificationNumber);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import site.timecapsulearchive.core.domain.group.entity.GroupInvite;
import site.timecapsulearchive.core.domain.group.entity.MemberGroup;
import site.timecapsulearchive.core.domain.history.entity.History;
import site.timecapsulearchive.core.domain.member.util.MakeRandomNickNameUtil;
import site.timecapsulearchive.core.global.entity.BaseEntity;

@Entity
Expand Down Expand Up @@ -105,4 +106,7 @@ public void updatePhoneNumber(String phone) {
this.phone = phone;
}

public void updateNickName() {
this.nickname = MakeRandomNickNameUtil.makeRandomNickName();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package site.timecapsulearchive.core.domain.member.util;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ThreadLocalRandom;

public final class MakeRandomNickNameUtil {

private static final long DIVIDED_UNIT = 1000;
private static final int NUMBER_RANGE = 52;

private MakeRandomNickNameUtil() {
}


public static String makeRandomNickName() {
List<String> nick = new ArrayList<>(RandomNickName.NICK.getValue());
List<String> name = new ArrayList<>(RandomNickName.NAME.getValue());

// 0 ~ 999
String uniqueNumber = String.valueOf(System.currentTimeMillis() % DIVIDED_UNIT);

return nick.get(randomNumber()) + name.get(randomNumber()) + uniqueNumber;
}

private static int randomNumber() {
return ThreadLocalRandom.current().nextInt(NUMBER_RANGE);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package site.timecapsulearchive.core.domain.member.util;

import java.util.List;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

@Getter
@RequiredArgsConstructor
public enum RandomNickName {

NICK(
List.of(
"기분나쁜", "기분좋은", "신바람나는", "상쾌한", "짜릿한", "그리운", "자유로운",
"서운한", "울적한", "비참한", "위축되는", "긴장되는", "두려운", "당당한", "배부른", "수줍은",
"창피한", "멋있는", "열받은", "심심한", "잘생긴", "이쁜", "시끄러운", "신비로운", "따뜻한",
"신나는", "소심한", "씩씩한", "순수한", "담백한", "활기찬", "단호한", "은은한", "우아한",
"반짝이는", "신랄한", "센치한", "도도한", "행복한", "선명한", "애틋한", "깔끔한", "유쾌한",
"신선한", "산뜻한", "쾌활한", "훈훈한", "몽환적인", "쿨한", "흥분된", "완벽한", "존경받는"
)
),

NAME(
List.of(
"사자", "코끼리", "호랑이", "곰", "여우", "늑대", "너구리", "침팬치", "고릴라", "참새",
"고슴도치", "강아지", "고양이", "거북이", "토끼", "앵무새", "하이에나", "돼지", "하마", "원숭이",
"물소", "얼룩말", "치타", "악어", "기린", "수달", "염소", "다람쥐", "판다", "파이어폭스",
"오소리", "밍크", "레서판다", "기러기", "펭귄", "오리", "카멜레온", "비둘기", "앵무새", "햄스터", "코뿔소",
"푸들", "꿀벌", "돌고래", "별", "달팽이", "바다거북", "코알라", "타조", "하늘다람쥐", "기니피그", "조개"
)
);

private final List<String> value;
}

0 comments on commit 8848c84

Please sign in to comment.