From 8d8aca8425a46745f885cdf34255fc77271c3c63 Mon Sep 17 00:00:00 2001 From: eckrin Date: Wed, 22 Nov 2023 15:26:47 +0900 Subject: [PATCH 1/2] =?UTF-8?q?chore:=20=ED=9A=8C=EC=9B=90=EA=B0=80?= =?UTF-8?q?=EC=9E=85=20=EB=8B=89=EB=84=A4=EC=9E=84=20=EC=A4=91=EB=B3=B5?= =?UTF-8?q?=ED=99=95=EC=9D=B8=20=EB=A1=9C=EC=A7=81=20AuthController?= =?UTF-8?q?=EC=AA=BD=EC=9C=BC=EB=A1=9C=20=EC=9D=B4=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/kusitms/jipbap/auth/AuthController.java | 7 +++++++ src/main/java/com/kusitms/jipbap/auth/AuthService.java | 6 ++++++ .../kusitms/jipbap/config/SpringSecurityConfig.java | 3 +-- .../java/com/kusitms/jipbap/user/UserController.java | 10 +--------- src/main/java/com/kusitms/jipbap/user/UserService.java | 4 ---- 5 files changed, 15 insertions(+), 15 deletions(-) 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..9385524 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,5 @@ 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())); - } } diff --git a/src/main/java/com/kusitms/jipbap/user/UserService.java b/src/main/java/com/kusitms/jipbap/user/UserService.java index 7f069a4..aa78df1 100644 --- a/src/main/java/com/kusitms/jipbap/user/UserService.java +++ b/src/main/java/com/kusitms/jipbap/user/UserService.java @@ -48,9 +48,5 @@ public void logout(String email) { user.updateRefreshToken(null); } - public String checkNicknameIsDuplicate(String nickname){ - if(userRepository.existsByUsername(nickname)) throw new UsernameExistsException("이미 존재하는 닉네임입니다."); - return "사용 가능한 닉네임입니다."; - } } From 0df7033e803a84e44271268c9015cba14c6f2ea9 Mon Sep 17 00:00:00 2001 From: eckrin Date: Wed, 22 Nov 2023 15:28:52 +0900 Subject: [PATCH 2/2] =?UTF-8?q?feat:=20=EB=8B=89=EB=84=A4=EC=9E=84=20?= =?UTF-8?q?=EC=A0=95=EB=B3=B4=20=EB=B0=9B=EC=95=84=EC=98=A4=EA=B8=B0=20api?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/kusitms/jipbap/user/UserController.java | 5 +++++ src/main/java/com/kusitms/jipbap/user/UserService.java | 10 ++++++++++ 2 files changed, 15 insertions(+) diff --git a/src/main/java/com/kusitms/jipbap/user/UserController.java b/src/main/java/com/kusitms/jipbap/user/UserController.java index 9385524..adb2d07 100644 --- a/src/main/java/com/kusitms/jipbap/user/UserController.java +++ b/src/main/java/com/kusitms/jipbap/user/UserController.java @@ -29,5 +29,10 @@ public CommonResponse logout(@Auth AuthInfo authInfo) { return new CommonResponse<>("로그아웃 성공"); } + @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 aa78df1..1838d3c 100644 --- a/src/main/java/com/kusitms/jipbap/user/UserService.java +++ b/src/main/java/com/kusitms/jipbap/user/UserService.java @@ -48,5 +48,15 @@ public void logout(String email) { user.updateRefreshToken(null); } + /** + * 유저 닉네임 받아오기 + * @param email + * @return + */ + @Transactional + public String getUserNickname(String email) { + User user = userRepository.findByEmail(email).orElseThrow(()->new InvalidEmailException("회원정보가 존재하지 않습니다.")); + return user.getUsername(); + } }