diff --git a/build.gradle b/build.gradle index 5aa3add..5fbca6f 100644 --- a/build.gradle +++ b/build.gradle @@ -53,3 +53,5 @@ dependencies { tasks.named('test') { useJUnitPlatform() } + + diff --git a/src/main/java/goorm/unit/booklog/common/config/SecurityConfig.java b/src/main/java/goorm/unit/booklog/common/config/SecurityConfig.java index e134386..4bbf30d 100644 --- a/src/main/java/goorm/unit/booklog/common/config/SecurityConfig.java +++ b/src/main/java/goorm/unit/booklog/common/config/SecurityConfig.java @@ -59,8 +59,10 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { "/error", "/favicon.ico", "/index.html", + "/api/v1/users/duplication", "/api/v1/users/signup", "/api/v1/auth/login" + }; CorsConfigurationSource corsConfigurationSource() { diff --git a/src/main/java/goorm/unit/booklog/domain/user/application/UserService.java b/src/main/java/goorm/unit/booklog/domain/user/application/UserService.java index 9eb6464..fd85cf9 100644 --- a/src/main/java/goorm/unit/booklog/domain/user/application/UserService.java +++ b/src/main/java/goorm/unit/booklog/domain/user/application/UserService.java @@ -20,7 +20,6 @@ public class UserService { @Transactional public UserPersistResponse createUser(UserCreateRequest request) { - validateIdDuplication(request.id()); User user = User.create( request.id(), request.name(), @@ -30,7 +29,7 @@ public UserPersistResponse createUser(UserCreateRequest request) { return UserPersistResponse.of(id); } - public void validateIdDuplication(String id) { + public void validateIdDuplication (String id) { if(userRepository.existsById(id)) { throw new UserIdDuplicatedException(); } diff --git a/src/main/java/goorm/unit/booklog/domain/user/presentation/UserController.java b/src/main/java/goorm/unit/booklog/domain/user/presentation/UserController.java index 69b5c1b..9c8a34a 100644 --- a/src/main/java/goorm/unit/booklog/domain/user/presentation/UserController.java +++ b/src/main/java/goorm/unit/booklog/domain/user/presentation/UserController.java @@ -15,6 +15,7 @@ import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; import static org.springframework.http.HttpStatus.CREATED; +import static org.springframework.http.HttpStatus.OK; @RestController @RequiredArgsConstructor @@ -29,11 +30,6 @@ public class UserController { responseCode="201", description="유저 생성 성공", content=@Content(schema=@Schema(implementation = UserPersistResponse.class)) - ), - @ApiResponse( - responseCode="409", - description="유저 생성 성공", - content=@Content(schema=@Schema(implementation = ExceptionResponse.class)) ) }) @ResponseStatus(CREATED) @@ -44,5 +40,26 @@ public ResponseEntity createUser( UserPersistResponse response = userService.createUser(request); return ResponseEntity.status(CREATED).body(response); } + + @Operation(summary="아이디 중복 체크", description="아이디의 중복 여부를 체크합니다.") + @ApiResponses({ + @ApiResponse( + responseCode="200", + description="아이디 사용 가능" + ), + @ApiResponse( + responseCode="409", + description="아이디 중복됨", + content=@Content(schema=@Schema(implementation = ExceptionResponse.class)) + ) + }) + @GetMapping("/duplication") + public ResponseEntity checkUseridDuplication( + @RequestParam String id + ) { + userService.validateIdDuplication(id); + return ResponseEntity.status(OK).build(); + } } +