Skip to content

Commit

Permalink
refactor: UserService에서 uid로 User를 찾는 로직 공통화
Browse files Browse the repository at this point in the history
  • Loading branch information
seungyeop-lee committed Jun 28, 2024
1 parent 729a925 commit 22911ed
Showing 1 changed file with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ public SocialUser signUpFromSocial(@Valid SignUpFromSocialCommand command) {
}

public User getByUid(@NotBlank String uid) {
return repository.findByUid(uid).orElseThrow(UserNotFoundException::new);
return getUserByUid(uid);
}

public void register(@Valid RegisterCommand command) {
User user = repository.findByUid(command.userUid()).orElseThrow();
User user = getUserByUid(command.userUid());
if (user.isRegistered()) {
throw new AlreadyRegisteredException();
}
Expand All @@ -58,7 +58,7 @@ public void register(@Valid RegisterCommand command) {
}

public void onboarding(@Valid OnboardingCommand command) {
User user = repository.findByUid(command.userUid()).orElseThrow();
User user = getUserByUid(command.userUid());
if (!user.isReadyToOnboarding()) {
throw new NotReadyToOnboardingException();
}
Expand All @@ -73,18 +73,22 @@ public void updateInfo(
@NotBlank String uid,
@NotBlank @Size(min = 1, max = 10) String nickname
) {
User user = repository.findByUid(uid).orElseThrow();
User user = getUserByUid(uid);
if (!user.isRegistered()) {
throw new NotRegisteredException();
}
user.update(nickname);
}

public void withdraw(@NotBlank String uid) {
User user = repository.findByUid(uid).orElseThrow();
User user = getUserByUid(uid);
if (user.isWithdrawn()) {
return;
}
user.withdraw();
}

private User getUserByUid(String uid) {
return repository.findByUid(uid).orElseThrow(UserNotFoundException::new);
}
}

0 comments on commit 22911ed

Please sign in to comment.