diff --git a/src/main/java/com/kusitms/jipbap/auth/AuthController.java b/src/main/java/com/kusitms/jipbap/auth/AuthController.java index 6eed1c9..0fc26a1 100644 --- a/src/main/java/com/kusitms/jipbap/auth/AuthController.java +++ b/src/main/java/com/kusitms/jipbap/auth/AuthController.java @@ -4,6 +4,7 @@ import com.kusitms.jipbap.common.response.CommonResponse; import com.kusitms.jipbap.security.Auth; import com.kusitms.jipbap.security.AuthInfo; +import com.kusitms.jipbap.user.dto.NicknameValidateRequest; import io.swagger.v3.oas.annotations.Operation; import lombok.RequiredArgsConstructor; import org.springframework.http.HttpStatus; @@ -39,4 +40,10 @@ public CommonResponse kakaoVerification(@RequestBody Kak return new CommonResponse<>(authService.kakaoAutoSignIn(authService.getKakaoProfile(dto.getToken()))); } + @Operation(summary = "닉네임 중복 여부 확인") + @PostMapping("/nickname/duplicate") + public CommonResponse checkNicknameIsDuplicate(@RequestBody NicknameValidateRequest dto) { + return new CommonResponse<>(authService.checkNicknameIsDuplicate(dto.getNickname())); + } + } diff --git a/src/main/java/com/kusitms/jipbap/auth/AuthService.java b/src/main/java/com/kusitms/jipbap/auth/AuthService.java index 748392e..4c58848 100644 --- a/src/main/java/com/kusitms/jipbap/auth/AuthService.java +++ b/src/main/java/com/kusitms/jipbap/auth/AuthService.java @@ -164,4 +164,10 @@ public KakaoSignInResponseDto kakaoAutoSignIn(KakaoProfileDto profile) { findUser.updateOAuth(KAKAO); return new KakaoSignInResponseDto(signIn(kakaoUser.getEmail(), kakaoUser.getPassword()), isSignUp); } + + @Transactional + public String checkNicknameIsDuplicate(String nickname){ + if(userRepository.existsByUsername(nickname)) throw new UsernameExistsException("이미 존재하는 닉네임입니다."); + return "사용 가능한 닉네임입니다."; + } } diff --git a/src/main/java/com/kusitms/jipbap/config/SpringSecurityConfig.java b/src/main/java/com/kusitms/jipbap/config/SpringSecurityConfig.java index 1a54df4..e265e98 100644 --- a/src/main/java/com/kusitms/jipbap/config/SpringSecurityConfig.java +++ b/src/main/java/com/kusitms/jipbap/config/SpringSecurityConfig.java @@ -66,8 +66,7 @@ public WebSecurityCustomizer webSecurityCustomizer() { "/auth/**", "/ws/**", //ws://localhost:8080/ws/chat "/ws-stomp/**", - "/addresses/**", - "/users/nickname" + "/addresses/**" ); } } \ No newline at end of file diff --git a/src/main/java/com/kusitms/jipbap/user/UserController.java b/src/main/java/com/kusitms/jipbap/user/UserController.java index f5fbb31..adb2d07 100644 --- a/src/main/java/com/kusitms/jipbap/user/UserController.java +++ b/src/main/java/com/kusitms/jipbap/user/UserController.java @@ -7,10 +7,7 @@ import com.kusitms.jipbap.user.dto.NicknameValidateRequest; import io.swagger.v3.oas.annotations.Operation; import lombok.RequiredArgsConstructor; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; @RequiredArgsConstructor @RestController @@ -32,10 +29,10 @@ public CommonResponse logout(@Auth AuthInfo authInfo) { return new CommonResponse<>("로그아웃 성공"); } - @Operation(summary = "닉네임 중복 여부 확인") - @PostMapping("/nickname") - public CommonResponse checkNicknameIsDuplicate(@RequestBody NicknameValidateRequest dto) { - return new CommonResponse<>(userService.checkNicknameIsDuplicate(dto.getNickname())); + @Operation(summary = "유저 닉네임 정보 받아오기") + @GetMapping("/nickname") + public CommonResponse getUserNickname(@Auth AuthInfo authInfo) { + return new CommonResponse<>(userService.getUserNickname(authInfo.getEmail())); } } diff --git a/src/main/java/com/kusitms/jipbap/user/UserService.java b/src/main/java/com/kusitms/jipbap/user/UserService.java index 7f069a4..1838d3c 100644 --- a/src/main/java/com/kusitms/jipbap/user/UserService.java +++ b/src/main/java/com/kusitms/jipbap/user/UserService.java @@ -48,9 +48,15 @@ public void logout(String email) { user.updateRefreshToken(null); } - public String checkNicknameIsDuplicate(String nickname){ - if(userRepository.existsByUsername(nickname)) throw new UsernameExistsException("이미 존재하는 닉네임입니다."); - return "사용 가능한 닉네임입니다."; + /** + * 유저 닉네임 받아오기 + * @param email + * @return + */ + @Transactional + public String getUserNickname(String email) { + User user = userRepository.findByEmail(email).orElseThrow(()->new InvalidEmailException("회원정보가 존재하지 않습니다.")); + return user.getUsername(); } }