Skip to content

Commit 3b3bc43

Browse files
committed
MOSU-308 feat: 카카오 중복 판단 로직 추가
1 parent 4192592 commit 3b3bc43

4 files changed

Lines changed: 36 additions & 13 deletions

File tree

src/main/java/life/mosu/mosuserver/application/auth/processor/SignUpAccountStepProcessor.java

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,28 @@ public class SignUpAccountStepProcessor implements StepProcessor<UserJpaEntity,
2020
@Transactional
2121
@Override
2222
public UserJpaEntity process(UserJpaEntity user) {
23-
if (userRepository.existsByPhoneNumber(user.getOriginPhoneNumber())) {
24-
throw new CustomRuntimeException(ErrorCode.USER_ALREADY_EXISTS);
25-
} else if (userRepository.existsByLoginId(user.getLoginId())) {
23+
24+
validateForNewSignUp(user);
25+
26+
return userRepository.save(user);
27+
}
28+
29+
private void validateForNewSignUp(UserJpaEntity user) {
30+
31+
userRepository.findByPhoneNumber(user.getOriginPhoneNumber())
32+
.ifPresent(existingUser -> {
33+
if (existingUser.isPendingUser()) {
34+
switch (existingUser.getProvider()) {
35+
case MOSU:
36+
throw new CustomRuntimeException(ErrorCode.USER_ALREADY_EXISTS);
37+
case KAKAO:
38+
throw new CustomRuntimeException(ErrorCode.KAKAO_DUPLICATED);
39+
}
40+
}
41+
});
42+
43+
if (userRepository.existsByLoginId(user.getLoginId())) {
2644
throw new CustomRuntimeException(ErrorCode.USER_ALREADY_EXISTS);
2745
}
28-
log.info("Processing user sign-up: {}", user);
29-
return userRepository.save(user);
3046
}
3147
}

src/main/java/life/mosu/mosuserver/application/oauth/OAuthUserPersistenceProcessor.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,21 @@ public class OAuthUserPersistenceProcessor implements StepProcessor<OAuthUserInf
1717

1818
private final UserJpaRepository userRepository;
1919

20-
/**
21-
* this method is processing OAuthUserInfo to UserJpaEntity that is Get or Create.
22-
*
23-
* @param info
24-
* @return
25-
*/
2620
@Override
2721
@Transactional
2822
public UserJpaEntity process(final OAuthUserInfo info) {
2923
return userRepository.findByPhoneNumber(
3024
PhoneNumberUtil.formatPhoneNumber(info.phoneNumber()))
3125
.map(existingUser -> {
32-
if (existingUser.isMosuUser()) {
33-
throw new OAuthException("DUPLICATE");
26+
switch (existingUser.getProvider()) {
27+
case MOSU:
28+
if (existingUser.isPendingUser()) {
29+
throw new OAuthException("DUPLICATE");
30+
}
31+
case KAKAO:
32+
if (existingUser.isPendingUser()) {
33+
throw new OAuthException("KAKAO_DUPLICATE");
34+
}
3435
}
3536
existingUser.updateOAuthUser(
3637
info.gender(),

src/main/java/life/mosu/mosuserver/domain/user/entity/UserJpaEntity.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,10 @@ public boolean isMosuUser() {
113113
return this.provider.equals(AuthProvider.MOSU);
114114
}
115115

116+
public boolean isPendingUser() {
117+
return this.userRole.equals(UserRole.ROLE_PENDING);
118+
}
119+
116120
public void grantUserRole() {
117121
this.userRole = UserRole.ROLE_USER;
118122
}

src/main/java/life/mosu/mosuserver/global/exception/ErrorCode.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ public enum ErrorCode {
2828
INVALID_REFRESH_TOKEN(HttpStatus.UNAUTHORIZED, "유효하지 않은 리프레시 토큰입니다."),
2929
VERIFICATION_FAILED(HttpStatus.UNAUTHORIZED, "인증에 실패했습니다."),
3030

31+
KAKAO_DUPLICATED(HttpStatus.CONFLICT, "이미 존재하는 카카오 계정입니다."),
32+
3133
//토큰 관련 에러
3234
INVALID_SIGN_UP_TOKEN(HttpStatus.UNAUTHORIZED, "유효하지 않은 회원가입 인증 토큰입니다."),
3335
MISSING_SIGNUP_TOKEN(HttpStatus.BAD_REQUEST, "회원가입 인증 토큰이 누락되었습니다."),

0 commit comments

Comments
 (0)