-
Notifications
You must be signed in to change notification settings - Fork 1
refactor : 유저/내정보 조회 리팩토링 #207
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
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
5be9a03
refactor : 유저/내정보 조회 리팩토링
Dev-lemongrab f6d4da1
feat: 온보딩 로직 추가 개발
Dev-lemongrab 41ac07f
refactor : 유저 조회 쿼리 메서드 변경
Dev-lemongrab ef157f9
refactor : 닉네임 생성 방식 수정
Dev-lemongrab b79a502
feat : user onboarding 기능 추가
Dev-lemongrab 13e917d
feat : user onboarding 테스트 코드 작성
Dev-lemongrab f35f58f
Merge branch 'develop' of https://github.com/SWYP-team-2th/server int…
Dev-lemongrab f8394fc
docs : 온보딩 단계 추가
Dev-lemongrab d1b75b1
fix : import문 제거
Dev-lemongrab 2bb4eac
refactor : 닉네임 생성 시 번호부여 로직 반복 쿼리 제거 버전
Dev-lemongrab fa06388
test : 닉네임 생성 테스 추가
Dev-lemongrab 71f51bc
test : 테스트 코드 리팩토링
Dev-lemongrab 47e01be
fix : 불필요한 import 문 제거
Dev-lemongrab 51e578c
fix : 불필요한 로직 제거
Dev-lemongrab a9a0448
merge : develop과 병합
Dev-lemongrab d24b7f1
fix : error code 추가
Dev-lemongrab 5c5c3cf
fix : dto 검증 서비스단으로 이동
Dev-lemongrab 184bca4
fix : import 문 정리
Dev-lemongrab 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 hidden or 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 hidden or 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
33 changes: 32 additions & 1 deletion
33
src/main/java/com/chooz/user/application/NicknameGenerator.java
This file contains hidden or 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 |
|---|---|---|
| @@ -1,18 +1,49 @@ | ||
| package com.chooz.user.application; | ||
|
|
||
| import com.chooz.user.domain.NicknameAdjectiveRepository; | ||
| import com.chooz.user.domain.UserRepository; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.stereotype.Component; | ||
| import java.math.BigInteger; | ||
| import java.util.List; | ||
| import java.util.Set; | ||
| import java.util.TreeSet; | ||
|
|
||
| @Component | ||
| @RequiredArgsConstructor | ||
| public class NicknameGenerator { | ||
|
|
||
| private final NicknameAdjectiveRepository nicknameAdjectiveRepository; | ||
| private final UserRepository userRepository; | ||
|
|
||
| public String generate() { | ||
| return nicknameAdjectiveRepository.findRandomNicknameAdjective() | ||
| String prefix = nicknameAdjectiveRepository.findRandomNicknameAdjective() | ||
| .map(adjective -> adjective.getAdjective() + " 츄") | ||
| .orElse("숨겨진 츄"); | ||
| return makeNickname(prefix); | ||
| } | ||
| private String makeNickname(String prefix) { | ||
| List<String> nickNames = userRepository.findNicknamesByPrefix(prefix); | ||
| Set<BigInteger> usedSuffixes = getUsedSuffixes(prefix, nickNames); | ||
| return findUsableNickname(prefix, usedSuffixes); | ||
| } | ||
| private Set<BigInteger> getUsedSuffixes(String prefix, List<String> nickNames) { | ||
| Set<BigInteger> usedSuffixes = new TreeSet<>(BigInteger::compareTo); | ||
| for(String nickName : nickNames) { | ||
| String suffix = nickName.substring(prefix.length()); | ||
| if(suffix.isEmpty()) { | ||
| usedSuffixes.add(BigInteger.ZERO); | ||
| }else{ | ||
| usedSuffixes.add(new BigInteger(suffix)); | ||
| } | ||
| } | ||
| return usedSuffixes; | ||
| } | ||
| private String findUsableNickname(String prefix, Set<BigInteger> usedSuffixes) { | ||
| BigInteger suffix = BigInteger.ZERO; | ||
| while (usedSuffixes.contains(suffix)) { | ||
| suffix = suffix.add(BigInteger.ONE); | ||
| } | ||
| return suffix.signum() == 0 ? prefix : prefix + suffix; | ||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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,46 @@ | ||
| package com.chooz.user.domain; | ||
|
|
||
| import com.chooz.common.domain.BaseEntity; | ||
| import jakarta.persistence.Entity; | ||
| import jakarta.persistence.GeneratedValue; | ||
| import jakarta.persistence.GenerationType; | ||
| import jakarta.persistence.Id; | ||
| import jakarta.persistence.Table; | ||
| import lombok.Builder; | ||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
|
|
||
|
|
||
| @Getter | ||
| @Entity | ||
| @Table(name = "onboarding_step") | ||
| @NoArgsConstructor(access = lombok.AccessLevel.PROTECTED) | ||
| public class OnboardingStep extends BaseEntity { | ||
|
|
||
| @Id | ||
| @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
| private Long id; | ||
|
|
||
| private boolean welcomeGuide; | ||
|
|
||
| private boolean firstVote; | ||
|
|
||
| @Builder | ||
| public OnboardingStep(Long id, boolean welcomeGuide, boolean firstVote) { | ||
| this.id = id; | ||
| this.welcomeGuide = welcomeGuide; | ||
| this.firstVote = firstVote; | ||
| } | ||
|
|
||
| public void completeWelcomeGuide() { | ||
| this.welcomeGuide = true; | ||
| } | ||
|
|
||
| public void completeFirstVote() { | ||
| this.firstVote = true; | ||
| } | ||
|
|
||
| public boolean isCompletedAll() { | ||
| return welcomeGuide && firstVote; | ||
| } | ||
| } |
7 changes: 7 additions & 0 deletions
7
src/main/java/com/chooz/user/domain/OnboardingStepRepository.java
This file contains hidden or 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.chooz.user.domain; | ||
|
|
||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
| import org.springframework.stereotype.Repository; | ||
|
|
||
| @Repository | ||
| public interface OnboardingStepRepository extends JpaRepository<OnboardingStep, Long> {} |
27 changes: 27 additions & 0 deletions
27
src/main/java/com/chooz/user/domain/OnboardingStepType.java
This file contains hidden or 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.chooz.user.domain; | ||
|
|
||
|
|
||
| import java.util.function.Consumer; | ||
| import java.util.function.Predicate; | ||
|
|
||
| public enum OnboardingStepType { | ||
|
|
||
| WELCOME_GUIDE(OnboardingStep::completeWelcomeGuide, OnboardingStep::isWelcomeGuide), | ||
| FIRST_VOTE(OnboardingStep::completeFirstVote, OnboardingStep::isFirstVote); | ||
|
|
||
| private final Consumer<OnboardingStep> action; | ||
| private final Predicate<OnboardingStep> checker; | ||
|
|
||
| OnboardingStepType(Consumer<OnboardingStep> action, Predicate<OnboardingStep> checker) { | ||
| this.action = action; | ||
| this.checker = checker; | ||
| } | ||
|
|
||
| public void apply(OnboardingStep step) { | ||
| this.action.accept(step); | ||
| } | ||
|
|
||
| public boolean check(OnboardingStep step) { | ||
| return this.checker.test(step); | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,8 +1,20 @@ | ||
| package com.chooz.user.domain; | ||
|
|
||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
| import org.springframework.data.jpa.repository.Query; | ||
| import org.springframework.data.repository.query.Param; | ||
| import org.springframework.stereotype.Repository; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| @Repository | ||
| public interface UserRepository extends JpaRepository<User, Long> { | ||
| @Query(""" | ||
| SELECT u.nickname | ||
| FROM User u | ||
| WHERE u.nickname | ||
| LIKE CONCAT(:prefix, '%') | ||
| """) | ||
| List<String> findNicknamesByPrefix(@Param("prefix") String prefix); | ||
|
|
||
| } |
This file contains hidden or 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
13 changes: 13 additions & 0 deletions
13
src/main/java/com/chooz/user/presentation/dto/OnboardingRequest.java
This file contains hidden or 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.chooz.user.presentation.dto; | ||
|
|
||
| import com.chooz.user.domain.OnboardingStepType; | ||
| import jakarta.validation.constraints.NotNull; | ||
| import jakarta.validation.constraints.Size; | ||
|
|
||
| import java.util.Map; | ||
|
|
||
| public record OnboardingRequest( | ||
| @NotNull | ||
| @Size(min = 1) | ||
| Map<OnboardingStepType, Boolean> onboardingStep | ||
| ) {} |
Oops, something went wrong.
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.
그냥 단순하게 최대값 + 1으로 하는 방식은 어떠신가요?
지금 방식대로 하면 중간에 없는 숫자를 재사용할 수 있어서 좋긴 한데 그냥 단순한게 더 좋지 않나 싶어서 여쭤봅니다
물론 이대로 하셔도 괜찮습니다!
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.
그럴까하다가 진호님이 좋아할 것 같아서...