Skip to content

[FEAT] 닉네임 중복 방지 API 구현 (#321)#322

Merged
lingard1234 merged 5 commits intodevfrom
feat/321-nickdup
Feb 8, 2026
Merged

[FEAT] 닉네임 중복 방지 API 구현 (#321)#322
lingard1234 merged 5 commits intodevfrom
feat/321-nickdup

Conversation

@lingard1234
Copy link
Copy Markdown
Contributor

Summary

@GetMapping("/nickname/available") 엔드포인트 생성

Changes

usercontroller, service, swagger, dto 추가

Type of Change

  • Bug fix (기존 기능에 영향을 주지 않는 버그 수정)
  • New feature (기존 기능에 영향을 주지 않는 새로운 기능 추가)
  • Breaking change (기존 기능에 영향을 주는 수정)
  • Refactoring (기능 변경 없는 코드 개선)
  • Documentation (문서 수정)
  • Chore (빌드, 설정 등 기타 변경)
  • Release (develop → main 배포)

Related Issues

Closes #321

참고 사항

@lingard1234 lingard1234 self-assigned this Feb 8, 2026
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @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

  • 닉네임 중복 방지 API 추가: 사용자 닉네임의 유효성 검사 및 중복 여부를 확인하는 새로운 /nickname/available GET 엔드포인트가 추가되었습니다.
  • UserService 기능 확장: UserService에 isNicknameAvailable 메서드가 추가되어 닉네임의 null/공백 여부, 길이(2~10자), 형식(한글, 영문, 숫자만), 그리고 데이터베이스 중복 여부를 검사합니다.
  • 새로운 응답 DTO 도입: 닉네임 사용 가능 여부를 나타내는 NicknameAvailableResponseDto 레코드 클래스가 새로 생성되었습니다.
  • Swagger 문서 업데이트: 새로 추가된 닉네임 중복 체크 API에 대한 상세한 Swagger 문서가 추가되어 API 사용법과 유효성 검사 규칙을 명확히 설명합니다.
Changelog
  • src/main/java/com/example/RealMatch/user/application/service/UserService.java
    • isNicknameAvailable 메서드 추가 (닉네임 유효성 및 중복 검사 로직 포함).
  • src/main/java/com/example/RealMatch/user/presentation/controller/UserController.java
    • /nickname/available GET 엔드포인트 추가.
    • NicknameAvailableResponseDto 임포트.
  • src/main/java/com/example/RealMatch/user/presentation/dto/response/NicknameAvailableResponseDto.java
    • NicknameAvailableResponseDto 레코드 클래스 신규 생성.
  • src/main/java/com/example/RealMatch/user/presentation/swagger/UserSwagger.java
    • checkNicknameAvailable 메서드에 대한 Swagger Operation 및 ApiResponses 어노테이션 추가.
    • NicknameAvailableResponseDto 임포트.
Activity
  • 닉네임 중복 방지 API를 구현하는 새로운 기능이 추가되었습니다.
  • 이 PR은 이슈 #321을 해결합니다.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

닉네임 중복 확인 API 추가를 위한 PR입니다. 전반적인 구현은 좋으나, 서비스 로직이 API 명세(Swagger)와 일치하지 않는 부분이 있습니다. 닉네임 유효성 검사 실패 시 400 에러를 반환하도록 명시되어 있지만, 현재 코드는 항상 200 OK를 반환합니다. 이 부분을 수정하여 API 계약을 준수하도록 하는 것이 중요합니다. 또한, 중복된 유효성 검사 로직을 별도의 컴포넌트로 추출하여 재사용성을 높이는 리팩토링 기회도 있습니다. 자세한 내용은 코드 리뷰 코멘트를 참고해주세요.

Comment on lines +170 to +196
@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);
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

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
  1. Extract duplicate validation logic into a separate component (e.g., a validator class) to reduce code duplication and improve maintainability.

@lingard1234 lingard1234 merged commit 15bec4a into dev Feb 8, 2026
1 check passed
@lingard1234 lingard1234 deleted the feat/321-nickdup branch February 8, 2026 09:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE] 닉네임 중복 API

1 participant