Conversation
Summary of ChangesHello @lingard1234, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! 이 PR은 사용자 닉네임의 유효성을 검사하고 중복 여부를 확인하는 새로운 API를 도입합니다. 이는 회원가입 및 닉네임 변경 과정에서 유효하고 고유한 닉네임을 보장하여 사용자 경험을 개선하고 데이터 무결성을 유지하는 데 기여합니다. Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
닉네임 중복 확인 API 추가를 위한 PR입니다. 전반적인 구현은 좋으나, 서비스 로직이 API 명세(Swagger)와 일치하지 않는 부분이 있습니다. 닉네임 유효성 검사 실패 시 400 에러를 반환하도록 명시되어 있지만, 현재 코드는 항상 200 OK를 반환합니다. 이 부분을 수정하여 API 계약을 준수하도록 하는 것이 중요합니다. 또한, 중복된 유효성 검사 로직을 별도의 컴포넌트로 추출하여 재사용성을 높이는 리팩토링 기회도 있습니다. 자세한 내용은 코드 리뷰 코멘트를 참고해주세요.
| @Transactional(readOnly = true) | ||
| public boolean isNicknameAvailable(String nickname) { | ||
|
|
||
| // 1. null / 공백 | ||
| if (nickname == null) { | ||
| return false; | ||
| } | ||
|
|
||
| nickname = nickname.trim(); | ||
| if (nickname.isEmpty()) { | ||
| return false; | ||
| } | ||
|
|
||
| // 2. 길이 체크 (사람 기준 2~10자) | ||
| int length = nickname.codePointCount(0, nickname.length()); | ||
| if (length < 2 || length > 10) { | ||
| return false; | ||
| } | ||
|
|
||
| // 3. 형식 체크 (한글, 영문, 숫자만) | ||
| if (!nickname.matches("^[가-힣a-zA-Z0-9]+$")) { | ||
| return false; | ||
| } | ||
|
|
||
| // 4. 중복 체크 | ||
| return !userRepository.existsByNickname(nickname); | ||
| } |
There was a problem hiding this comment.
Swagger 문서(@ApiResponses)에 따르면 닉네임의 형식이나 길이가 유효하지 않을 경우 400 Bad Request를 반환해야 합니다. 하지만 현재 isNicknameAvailable 메소드는 유효성 검사에 실패할 경우 false를 반환하여, 컨트롤러에서 항상 200 OK와 { "available": false } 응답을 보내게 됩니다. 이는 API 명세와 구현 간의 불일치입니다.
유효성 검사에 실패했을 때 false를 반환하는 대신 CustomException을 발생시켜 전역 예외 처리기에서 적절한 400번대 에러 응답을 생성하도록 수정하는 것을 권장합니다. 이렇게 하면 API 명세를 준수하고 클라이언트에게 더 명확한 에러 원인을 전달할 수 있습니다.
더불어, 이 닉네임 유효성 검사 로직은 updateMyInfo 메소드에도 중복으로 존재합니다. 이번 기회에 중복되는 로직을 별도의 private 메소드로 추출하여 재사용성을 높이는 리팩토링을 고려해보시는 것도 좋겠습니다.
@Transactional(readOnly = true)
public boolean isNicknameAvailable(String nickname) {
// 1. null / 공백 체크
if (nickname == null || nickname.trim().isEmpty()) {
throw new CustomException(UserErrorCode.INVALID_NICKNAME_FORMAT);
}
nickname = nickname.trim();
// 2. 길이 체크 (사람 기준 2~10자)
int length = nickname.codePointCount(0, nickname.length());
if (length < 2 || length > 10) {
throw new CustomException(UserErrorCode.INVALID_NICKNAME_LENGTH);
}
// 3. 형식 체크 (한글, 영문, 숫자만)
if (!nickname.matches("^[가-힣a-zA-Z0-9]+$")) {
throw new CustomException(UserErrorCode.INVALID_NICKNAME_FORMAT);
}
// 4. 중복 체크
return !userRepository.existsByNickname(nickname);
}References
- Extract duplicate validation logic into a separate component (e.g., a validator class) to reduce code duplication and improve maintainability.
Summary
@GetMapping("/nickname/available") 엔드포인트 생성
Changes
usercontroller, service, swagger, dto 추가
Type of Change
Related Issues
Closes #321
참고 사항