Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

닉네임 관련 api 추가, 변경 #72

Merged
merged 2 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/main/java/com/kusitms/jipbap/auth/AuthController.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -39,4 +40,10 @@ public CommonResponse<KakaoSignInResponseDto> kakaoVerification(@RequestBody Kak
return new CommonResponse<>(authService.kakaoAutoSignIn(authService.getKakaoProfile(dto.getToken())));
}

@Operation(summary = "닉네임 중복 여부 확인")
@PostMapping("/nickname/duplicate")
public CommonResponse<String> checkNicknameIsDuplicate(@RequestBody NicknameValidateRequest dto) {
return new CommonResponse<>(authService.checkNicknameIsDuplicate(dto.getNickname()));
}

}
6 changes: 6 additions & 0 deletions src/main/java/com/kusitms/jipbap/auth/AuthService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 "사용 가능한 닉네임입니다.";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ public WebSecurityCustomizer webSecurityCustomizer() {
"/auth/**",
"/ws/**", //ws://localhost:8080/ws/chat
"/ws-stomp/**",
"/addresses/**",
"/users/nickname"
"/addresses/**"
);
}
}
13 changes: 5 additions & 8 deletions src/main/java/com/kusitms/jipbap/user/UserController.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -32,10 +29,10 @@ public CommonResponse<String> logout(@Auth AuthInfo authInfo) {
return new CommonResponse<>("로그아웃 성공");
}

@Operation(summary = "닉네임 중복 여부 확인")
@PostMapping("/nickname")
public CommonResponse<String> checkNicknameIsDuplicate(@RequestBody NicknameValidateRequest dto) {
return new CommonResponse<>(userService.checkNicknameIsDuplicate(dto.getNickname()));
@Operation(summary = "유저 닉네임 정보 받아오기")
@GetMapping("/nickname")
public CommonResponse<String> getUserNickname(@Auth AuthInfo authInfo) {
return new CommonResponse<>(userService.getUserNickname(authInfo.getEmail()));
}
}

12 changes: 9 additions & 3 deletions src/main/java/com/kusitms/jipbap/user/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

Loading