Skip to content

Commit

Permalink
feat: 회원가입 중복 검증 로직 추가 (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
gardening-y committed Jan 8, 2024
1 parent 32d2c81 commit d0d3df7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public enum ErrorMessage {
* 409 Conflict
*/
CONFLICT(HttpStatus.CONFLICT, "e4090", "이미 존재하는 리소스입니다."),
DUPLICATE_USER(HttpStatus.CONFLICT, "e4091", "이미 존재하는 회원입니다."),

/**
* 500 Internal Server Error
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@

public interface UserRepository extends JpaRepository<User, Long> {
Optional<User> findUserByPlatformAndPlatformId(Platform platform, String platformId);

boolean existsUserByPlatformAndPlatformId(Platform platform, String platformId);
}

0 comments on commit d0d3df7

Please sign in to comment.