Skip to content

Commit

Permalink
Merge pull request #19 from 28th-meetup/feat/auth
Browse files Browse the repository at this point in the history
[fix] 온보딩시 닉네임 중복 미허용
  • Loading branch information
eckrin authored Nov 10, 2023
2 parents e6c2602 + c9c3412 commit 2f84d1e
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,11 @@ public CommonResponse<?> handleJsonException(JsonException e, HttpServletRequest
log.warn("Auth-005> 요청 URI: " + request.getRequestURI() + ", 에러 메세지: " + e.getMessage());
return new CommonResponse<>(ErrorCode.INTERNAL_SERVER_ERROR);
}

@ExceptionHandler(UsernameExistsException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
public CommonResponse<?> handleUsernameExistsException(UsernameExistsException e, HttpServletRequest request) {
log.warn("Auth-006> 요청 URI: " + request.getRequestURI() + ", 에러 메세지: " + e.getMessage());
return new CommonResponse<>(ErrorCode.EMAIL_EXISTS_ERROR);
}
}
1 change: 1 addition & 0 deletions src/main/java/com/kusitms/jipbap/auth/AuthService.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public class AuthService {
public void signUp(SignUpRequestDto dto) {

if(userRepository.existsByEmail(dto.getEmail())) throw new EmailExistsException("이미 가입한 이메일입니다.");
if(userRepository.existsByUsername(dto.getUsername())) throw new UsernameExistsException("이미 존재하는 닉네임입니다.");
userRepository.save(
User.builder()
.id(null)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.kusitms.jipbap.auth.exception;

public class UsernameExistsException extends RuntimeException{
public UsernameExistsException(String message) {
super(message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public enum ErrorCode {
INVALID_PASSWORD_ERROR(false, HttpStatus.BAD_REQUEST.value(), "비밀번호를 확인해주세요. 카카오 계정이라면 카카오 로그인으로 시도해주세요."),
INVALID_ACCESS_TOKEN_ERROR(false, HttpStatus.BAD_REQUEST.value(), "AccessToken 정보를 찾을 수 없습니다."),
INVALID_REFRESH_TOKEN_ERROR(false, HttpStatus.BAD_REQUEST.value(), "RefreshToken 정보를 찾을 수 없습니다."),
USERNAME_EXISTS_ERROR(false, HttpStatus.BAD_REQUEST.value(), "이미 존재하는 닉네임입니다."),

//user
USER_NOT_FOUND_ERROR(false, HttpStatus.BAD_REQUEST.value(), "존재하지 않는 유저입니다."),
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/kusitms/jipbap/user/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class User extends DateEntity {
private String password; //비밀번호

@NotBlank
@Column(unique = true)
private String username; //닉네임

@NotBlank
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/kusitms/jipbap/user/UserRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@

public interface UserRepository extends JpaRepository<User, Long> {
boolean existsByEmail(String email);
boolean existsByUsername(String username);
Optional<User> findByEmail(String email);
}

0 comments on commit 2f84d1e

Please sign in to comment.