diff --git a/doorip-api/src/main/java/org/doorip/user/service/UserService.java b/doorip-api/src/main/java/org/doorip/user/service/UserService.java index 0fcbee8..ec242a5 100644 --- a/doorip-api/src/main/java/org/doorip/user/service/UserService.java +++ b/doorip-api/src/main/java/org/doorip/user/service/UserService.java @@ -4,6 +4,7 @@ import org.doorip.auth.jwt.JwtProvider; import org.doorip.auth.jwt.JwtValidator; import org.doorip.auth.jwt.Token; +import org.doorip.exception.ConflictException; import org.doorip.exception.EntityNotFoundException; import org.doorip.exception.UnauthorizedException; import org.doorip.message.ErrorMessage; @@ -49,6 +50,7 @@ public UserResponse signIn(String token, UserSignInRequest request) { public UserResponse signUp(String token, UserSignUpRequest request) { Platform enumPlatform = getEnumPlatformFromStringPlatform(request.platform()); String platformId = getPlatformId(token, enumPlatform); + validateDuplicateUser(enumPlatform, platformId); User savedUser = saveUser(request, platformId, enumPlatform); Token issueToken = jwtProvider.issueToken(savedUser.getId()); updateRefreshToken(issueToken.refreshToken(), savedUser); @@ -83,6 +85,12 @@ private String getPlatformId(String token, Platform platform) { return kakaoOAuthProvider.getKakaoPlatformId(token); } + private void validateDuplicateUser(Platform platform, String platformId) { + if (userRepository.existsUserByPlatformAndPlatformId(platform, platformId)) { + throw new ConflictException(ErrorMessage.DUPLICATE_USER); + } + } + private User getUser(Platform platform, String platformId) { return userRepository.findUserByPlatformAndPlatformId(platform, platformId) .orElseThrow(() -> new EntityNotFoundException(ErrorMessage.USER_NOT_FOUND)); diff --git a/doorip-common/src/main/java/org/doorip/message/ErrorMessage.java b/doorip-common/src/main/java/org/doorip/message/ErrorMessage.java index a4e6488..997a603 100644 --- a/doorip-common/src/main/java/org/doorip/message/ErrorMessage.java +++ b/doorip-common/src/main/java/org/doorip/message/ErrorMessage.java @@ -58,6 +58,7 @@ public enum ErrorMessage { * 409 Conflict */ CONFLICT(HttpStatus.CONFLICT, "e4090", "이미 존재하는 리소스입니다."), + DUPLICATE_USER(HttpStatus.CONFLICT, "e4091", "이미 존재하는 회원입니다."), /** * 500 Internal Server Error diff --git a/doorip-domain/src/main/java/org/doorip/user/repository/UserRepository.java b/doorip-domain/src/main/java/org/doorip/user/repository/UserRepository.java index 539531e..42be847 100644 --- a/doorip-domain/src/main/java/org/doorip/user/repository/UserRepository.java +++ b/doorip-domain/src/main/java/org/doorip/user/repository/UserRepository.java @@ -8,4 +8,6 @@ public interface UserRepository extends JpaRepository { Optional findUserByPlatformAndPlatformId(Platform platform, String platformId); + + boolean existsUserByPlatformAndPlatformId(Platform platform, String platformId); }