Skip to content

refactor(word): clean up API boundary handling#339

Merged
SolfE merged 6 commits into
developfrom
codex/word-api-boundary-cleanup
Jun 23, 2026
Merged

refactor(word): clean up API boundary handling#339
SolfE merged 6 commits into
developfrom
codex/word-api-boundary-cleanup

Conversation

@SolfE

@SolfE SolfE commented Jun 23, 2026

Copy link
Copy Markdown
Member

Summary

word 도메인의 API 경계 처리를 정리합니다.

  • 단어 응답 DTO 생성 책임을 WordResponseMapper로 분리
  • enum/request parameter 타입 변환 실패를 400 Bad Request로 처리
  • 관리자 강제 단어 분석 API의 입력 검증/정규화 경로를 일반 조회 API와 일치
  • 관리자 단어 컨트롤러에 @PreAuthorize("hasRole('ADMIN')") 명시
  • Meaning, RelatedForms를 DTO 패키지에서 도메인 공유 값 모델 패키지로 이동
  • WordsController 미사용 import 정리

Problem

기존 word API 경계에는 몇 가지 책임 혼재가 있었습니다.

  • WordService가 비즈니스 흐름과 응답 DTO 조립을 함께 담당했습니다.
  • 잘못된 enum 파라미터가 generic 예외 처리로 넘어갈 수 있었습니다.
  • 관리자 강제 분석 API가 일반 조회 API와 다른 입력 검증 경로를 탔습니다.
  • Meaning, RelatedForms가 DTO 패키지에 있으면서 엔티티 저장 모델에도 사용되었습니다.

Solution

컨트롤러, 서비스, DTO, 도메인 값 모델의 책임을 더 명확히 분리했습니다.

  • 복잡한 응답 조립은 WordResponseMapper로 위임했습니다.
  • 타입 변환 실패는 공통 예외 핸들러에서 INVALID_INPUT 기반 400 응답으로 처리합니다.
  • 관리자 API도 WordValidator를 통해 단어를 검증/정규화합니다.
  • word 도메인 내부에서 공유되는 값 모델은 word.model 패키지로 이동했습니다.

Changes

  • WordResponseMapper 추가
  • GlobalExceptionHandlerMethodArgumentTypeMismatchException 처리 추가
  • WordsAdminController 입력 검증 및 관리자 권한 명시
  • Meaning, RelatedForms 패키지 이동: word.dto -> word.model
  • 관련 단위 테스트 추가 및 수정

Example

잘못된 요청 파라미터:

GET /api/v1/words/run?targetLanguage=INVALID

이제 서버 내부 오류가 아니라 400 응답으로 처리됩니다.

{
  "message": "targetLanguage: 올바르지 않은 값입니다"
}

관리자 강제 분석 API도 입력 단어를 동일하게 정규화합니다.

Run! -> run

Validation

  • ./gradlew compileJava
  • ./gradlew test --tests com.linglevel.api.word.service.WordServiceTest
  • ./gradlew test --tests com.linglevel.api.common.handler.GlobalExceptionHandlerTest --tests com.linglevel.api.word.service.WordServiceTest
  • ./gradlew test --tests com.linglevel.api.word.controller.WordsAdminControllerTest --tests com.linglevel.api.word.service.WordServiceTest
  • ./gradlew test --tests com.linglevel.api.word.service.WordServiceTest --tests com.linglevel.api.word.service.WordVariantServiceTest --tests com.linglevel.api.word.controller.WordsAdminControllerTest --tests com.linglevel.api.word.validator.WordValidatorTest

Related Issues

  • N/A

@SolfE SolfE marked this pull request as ready for review June 23, 2026 13:31
@SolfE SolfE merged commit 10b933c into develop Jun 23, 2026
1 check passed
@SolfE SolfE deleted the codex/word-api-boundary-cleanup branch June 23, 2026 13:40
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.

1 participant