Skip to content

[Feat]: 경로 변수 및 요청 파라미터 유효성 검사#25

Merged
alexization merged 2 commits into
developfrom
refactor/phase4-dto-validation
Feb 1, 2026
Merged

[Feat]: 경로 변수 및 요청 파라미터 유효성 검사#25
alexization merged 2 commits into
developfrom
refactor/phase4-dto-validation

Conversation

@alexization
Copy link
Copy Markdown
Owner

@alexization alexization commented Feb 1, 2026

📌 개요

API 안정성과 보안 강화를 위해 입력값 검증을 추가했습니다. GitHub 사용자명 패턴 검증으로 잘못된 요청을 조기에 차단하고, 명확한 에러 메시지를 제공합니다.

🔗 관련 이슈

🛠 작업 내용

  • UserController 검증 추가

    • @validated 어노테이션 추가
    • username 경로 변수에 @pattern 검증 (GitHub 사용자명 규칙)
    • 패턴: 1-39자, 영문/숫자/하이픈, 하이픈으로 시작/끝 불가
  • RankingController 검증 추가

    • @validated 어노테이션 추가
    • page 파라미터에 @min(0) 검증
  • GlobalExceptionHandler 개선

    • ConstraintViolationException 핸들러 추가
    • 검증 실패 시 사용자 친화적 에러 메시지 반환

Summary by CodeRabbit

  • Bug Fixes

    • API 입력값 검증 강화 — 페이지 매개변수는 0 이상만 허용
    • 사용자명 형식 검사 추가 및 경로 변수 검증 활성화
    • 검증 실패 시 클라이언트에 명확한 400 응답과 설명 메시지 반환
  • New Features

    • 검증 예외에 대한 전역 처리기 추가로 일관된 오류 응답 제공

✏️ Tip: You can customize this high-level summary in your review settings.

- UserController: username 경로 변수에 GitHub 사용자명 패턴 검증 추가
- RankingController: page 파라미터에 최소값 검증 추가
- GlobalExceptionHandler: ConstraintViolationException 처리 추가
@alexization alexization self-assigned this Feb 1, 2026
@alexization alexization added the enhancement New feature or request label Feb 1, 2026
@alexization alexization linked an issue Feb 1, 2026 that may be closed by this pull request
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Feb 1, 2026

📝 Walkthrough

Walkthrough

컨트롤러 메서드 파라미터에 Bean Validation 애노테이션을 추가하고(@Min, @Pattern), 컨트롤러 클래스에 @Validated를 적용했으며, 전역 예외 처리기에 ConstraintViolationException 핸들러를 추가했습니다.

Changes

Cohort / File(s) Summary
컨트롤러 검증 추가
src/main/java/com/gitranker/api/domain/ranking/RankingController.java, src/main/java/com/gitranker/api/domain/user/UserController.java
RankingControllerpage 파라미터에 @Min(0, message = "...") 추가, UserControllerusername 경로 변수에 @Pattern(regexp = USERNAME_PATTERN, message = USERNAME_MESSAGE) 추가. 두 컨트롤러 클래스에 @Validated 적용 및 관련 import 추가.
전역 예외 처리
src/main/java/com/gitranker/api/global/error/GlobalExceptionHandler.java
jakarta.validation.ConstraintViolationException 처리용 핸들러 메서드 추가: 첫 위반 메시지 추출 후 경고 로깅 및 HTTP 400(ErrorType.INVALID_REQUEST) 응답 반환.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 검증의 울타리로 뛰어들었네,
잘못된 값엔 살짝 경고를,
예외는 부드럽게 잡아내고,
응답은 명확히 돌려주네,
코드 밭에 당근 한 줌의 품격 🥕

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed PR 제목이 변경사항의 핵심을 명확하게 요약하고 있습니다. 경로 변수(UserController의 username)와 요청 파라미터(RankingController의 page)에 대한 유효성 검사 추가가 주요 변경사항이며, 제목이 이를 정확하게 반영합니다.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch refactor/phase4-dto-validation

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@src/main/java/com/gitranker/api/domain/user/UserController.java`:
- Around line 24-42: Update the USERNAME_PATTERN constant to enforce GitHub
rules by forbidding consecutive hyphens and ensuring hyphens only appear between
alphanumeric characters while still enforcing the 1–39 character limit; replace
the current pattern value in the USERNAME_PATTERN constant used by getUser and
refreshUser with a regex that uses a negative lookahead to disallow "--",
asserts total length 1–39, and matches one or more alphanumerics optionally
separated by single hyphens (so hyphens cannot start/end or be adjacent).

Comment thread src/main/java/com/gitranker/api/domain/user/UserController.java Outdated
@alexization alexization merged commit 72369be into develop Feb 1, 2026
2 checks passed
@alexization alexization deleted the refactor/phase4-dto-validation branch February 1, 2026 08:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feat]: 요청 입력 검증 로직 추가

1 participant