Skip to content

Commit

Permalink
[BOOK-19]-아이디 중복 체크 API 분리 (#9)
Browse files Browse the repository at this point in the history
* [BOOK-19]-refactor: 아이디 중복 체크 API 분리

* [BOOK-19]-refactor: 불필요한 dto 제거
  • Loading branch information
sunny2you authored Oct 10, 2024
1 parent ddcaee4 commit f052d78
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 7 deletions.
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,5 @@ dependencies {
tasks.named('test') {
useJUnitPlatform()
}


Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ public class UserService {

@Transactional
public UserPersistResponse createUser(UserCreateRequest request) {
validateIdDuplication(request.id());
User user = User.create(
request.id(),
request.name(),
Expand All @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -44,5 +40,26 @@ public ResponseEntity<UserPersistResponse> 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<Void> checkUseridDuplication(
@RequestParam String id
) {
userService.validateIdDuplication(id);
return ResponseEntity.status(OK).build();
}
}


0 comments on commit f052d78

Please sign in to comment.