diff --git a/src/main/java/site/billbill/apiserver/api/auth/controller/AuthController.java b/src/main/java/site/billbill/apiserver/api/auth/controller/AuthController.java index dfd927c..bfac926 100644 --- a/src/main/java/site/billbill/apiserver/api/auth/controller/AuthController.java +++ b/src/main/java/site/billbill/apiserver/api/auth/controller/AuthController.java @@ -11,8 +11,10 @@ import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.*; import site.billbill.apiserver.api.auth.dto.request.*; +import site.billbill.apiserver.api.auth.dto.response.NicknameResponse; import site.billbill.apiserver.api.auth.service.AuthService; import site.billbill.apiserver.api.auth.service.OAuthService; +import site.billbill.apiserver.api.users.service.UserService; import site.billbill.apiserver.common.response.BaseResponse; import site.billbill.apiserver.common.utils.jwt.dto.JwtDto; @@ -30,6 +32,7 @@ public class AuthController { private final AuthService authService; private final OAuthService oAuthService; + private final UserService userService; @Operation(summary = "회원 가입(일반)", description = "일반 회원 가입 API") @ResponseStatus(HttpStatus.CREATED) @@ -64,4 +67,14 @@ public BaseResponse kakaoCallback(@RequestParam("code") String code) { public BaseResponse identity(@RequestBody IdentityVerificationRequest request) { return null; } + + @Operation(summary = "닉네임 중복검사", description = "닉네임 중복검사") + @ResponseStatus(HttpStatus.OK) + @GetMapping("/nickname") + public BaseResponse getNicknameValidity(@RequestParam String nickname) { + return new BaseResponse<>(NicknameResponse.builder() + .valid(authService.getNicknameValidity(nickname)) + .build()); + } + } diff --git a/src/main/java/site/billbill/apiserver/api/auth/dto/response/NicknameResponse.java b/src/main/java/site/billbill/apiserver/api/auth/dto/response/NicknameResponse.java new file mode 100644 index 0000000..38d8087 --- /dev/null +++ b/src/main/java/site/billbill/apiserver/api/auth/dto/response/NicknameResponse.java @@ -0,0 +1,10 @@ +package site.billbill.apiserver.api.auth.dto.response; + +import lombok.Builder; +import lombok.Data; + +@Data +@Builder +public class NicknameResponse { + private boolean valid; +} diff --git a/src/main/java/site/billbill/apiserver/api/auth/service/AuthService.java b/src/main/java/site/billbill/apiserver/api/auth/service/AuthService.java index 14667f6..54060ef 100644 --- a/src/main/java/site/billbill/apiserver/api/auth/service/AuthService.java +++ b/src/main/java/site/billbill/apiserver/api/auth/service/AuthService.java @@ -13,4 +13,6 @@ public interface AuthService { JwtDto reissue(String refreshToken); boolean identifyUser(IdentityRequest request); + + boolean getNicknameValidity(String nickname); } diff --git a/src/main/java/site/billbill/apiserver/api/auth/service/AuthServiceImpl.java b/src/main/java/site/billbill/apiserver/api/auth/service/AuthServiceImpl.java index b234eff..960b724 100644 --- a/src/main/java/site/billbill/apiserver/api/auth/service/AuthServiceImpl.java +++ b/src/main/java/site/billbill/apiserver/api/auth/service/AuthServiceImpl.java @@ -118,6 +118,11 @@ public boolean identifyUser(IdentityRequest request) { return false; } + @Override + public boolean getNicknameValidity(String nickname) { + return !userRepository.existsByNickname(nickname); + } + /** * Method that if user is withdrawn * diff --git a/src/main/java/site/billbill/apiserver/repository/user/UserRepository.java b/src/main/java/site/billbill/apiserver/repository/user/UserRepository.java index 9e56503..c5c0d37 100644 --- a/src/main/java/site/billbill/apiserver/repository/user/UserRepository.java +++ b/src/main/java/site/billbill/apiserver/repository/user/UserRepository.java @@ -10,4 +10,5 @@ public interface UserRepository extends JpaRepository, UserDslRepository { Optional findByUserIdAndWithdrawStatus(String userId, boolean withdrawStatus); Optional findByProviderId(String providerId); + boolean existsByNickname(String nickname); }