Skip to content

feat: 사용량 조회 API (#76) - #77

Open
ji2081 wants to merge 5 commits into
developfrom
feat/76-user-usage
Open

ji2081 wants to merge 5 commits into
developfrom
feat/76-user-usage

Conversation

@ji2081

@ji2081 ji2081 commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

관련 이슈

작업 내용

  • GET /api/v1/users/me/usage (명세 6번)
  • 보유 템플릿 수와 AI 톤 교정 오늘 사용량 조회
  • template·ai 서비스를 조합하므로 UserUsageQueryService로 분리 (순환 참조 방지)

명세와 달라진 점

  • 명세 6번 에러 표에 USER404_1 추가. #61에서 getTodayUsage의 회원 확인을 빼면서 조합 서비스에서 하기로 한 내용입니다.

테스트

전체 ./gradlew build 통과

  • 사용 기록 없음, 응답 필드, 리셋 시각 +09:00, 캐시 금지
  • 템플릿 한도 경계 49개·50개
  • 휴지통과 다른 회원의 템플릿 제외
  • AI 5회 사용, 어제와 다른 회원의 사용량 제외
  • 탈퇴·없는 회원 USER404_1, 토큰 없음 COMMON401_1

확인 체크리스트

  • ./gradlew build 통과
  • 테스트 포함
  • 변경 400줄 안팎 (운영 136, 테스트 182, 문서 3)
  • 병합된 마이그레이션 수정 안 함
  • 비밀 값·개인정보 없음
  • global 공통 코드 수정 없음

리뷰어에게

  • #75와 UserController, UserSuccessCode가 겹칩니다. 나중에 병합하는 쪽에서 양쪽을 합칠 예정입니다.

@ji2081 ji2081 self-assigned this Nov 5, 2026
@ji2081 ji2081 added feature 기능 개발 user 내 정보·사용량·플랜 판정 labels Nov 5, 2026
chjpooh2002
chjpooh2002 previously approved these changes Nov 9, 2026

@chjpooh2002 chjpooh2002 left a comment

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.

리뷰 남긴 사항 참고부탁드립니다!

Comment on lines +12 to +13
new TemplateUsage(templateCount, templateLimit, Math.max(templateLimit - templateCount, 0),
templateCount >= templateLimit),

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.

한도 도달 판단(templateCount >= templateLimit)이TemplateCommandService.validateTemplateLimit과 따로 있어요. 나중에 기준이 바뀌면 화면 표시와 실제 차단이 어긋날 수 있으니, 판단을 한 곳(예: UsageLimits나 template 쪽)에 두는 걸 고려하면 좋을 거 같습니다!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

반영했습니다! 한도 판단 규칙을 TemplateLimit(template/support)으로 만들고, 사용량 표시와 템플릿 저장 차단(validateTemplateLimit)이 둘 다 이 규칙을 쓰도록 바꿨습니다. 이제 한도 기준이 바뀌어도 한 곳만 고치면 화면과 실제 차단이 같이 바뀝니다.

숫자는 지금처럼 UsageLimits에 두고, 판단은 휴지통 30일 규칙(TrashRetention)처럼 템플릿 쪽 support에 뒀습니다. 규칙을 일부러 틀리게 바꿔 보니 템플릿 저장 테스트와 사용량 테스트가 함께 실패하는 것도 확인했습니다.

new AiToneUsage(aiTone.usedCount(), aiTone.limit(), aiTone.remaining(), aiTone.resetAt()));
}

public record TemplateUsage(long count, int limit, long remaining, @JsonProperty("isFull") boolean isFull) {

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.

(사소) count, remaining이 long인데 명세 타입은 Integer예요. #68에서 totalCount를 명세에 맞춰 int로 둔 것과 맞추면 좋을 것 같습니다!

@ji2081 ji2081 Nov 14, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

명세에 맞춰 count, remaining을 int로 바꿨습니다. 개수 조회인 countActive는 long이라 Math.toIntExact로 바꿔 받아 범위를 넘으면 바로 에러가 나게 처리했습니다.


/** 없거나 탈퇴한 회원이면 USER404_1. */
public UserUsageResult getUsage(Long userId) {
if (userRepository.findByIdAndDeletedAtIsNull(userId).isEmpty()) {

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.

존재 확인만 하는데 회원 엔티티 전체를 읽고 있어요. #73 의 getNickname, #75 의 getDetail에도 같은 "탈퇴하지 않은 회원 확인 → USER404_1" 코드가 있으니, 병합할 때 하나로 모으면 좋겠습니다!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

develop을 합치고 validateActive를 쓰도록 바꿨습니다! 이제 회원 확인은 그 메서드 하나로 모인 거 같습니다.

@ji2081

ji2081 commented Nov 14, 2026

Copy link
Copy Markdown
Contributor Author

@oTAETAEo 한도 판단을 한 곳으로 모으면서 TemplateCommandService.validateTemplateLimit의 조건 한 줄을 TemplateLimit.isReached(...)로 바꿨습니다. 동작은 그대로이고 기존 테스트도 수정 없이 통과합니다. 한 번 확인 부탁드립니다!

@oTAETAEo

Copy link
Copy Markdown
Contributor

@ji2081 확인했습니당 문제 없습니당 👍


@GetMapping("/me/usage")
public ResponseEntity<ApiResponse<UserUsageResponse>> getUsage(@LoginUser Long userId) {
return ApiResponse.success(UserSuccessCode.USAGE_FOUND, UserUsageResponse.from(userUsageQueryService.getUsage(userId)));

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.

(사소) 75 병합 후 UserController 충돌 풀 때 getUsage도 getMe처럼 결과를 변수(UserUsageResult result)로 받은 뒤 응답을 만드는 모양으로 맞춰 주세요!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

충돌 풀면서 getUsage도 결과를 변수로 받은 뒤 응답을 만드는 모양으로 맞췄습니다.

# Conflicts:
#	src/main/java/com/sniptext/domain/user/controller/UserController.java
#	src/main/java/com/sniptext/domain/user/controller/UserSuccessCode.java

@chjpooh2002 chjpooh2002 left a comment

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.

수고하셨습니다~~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature 기능 개발 user 내 정보·사용량·플랜 판정

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[feat] 사용량 조회 API

3 participants