Skip to content

feat(account): expose per-grant credit details in credits/info - #7280

Open
aimeritething wants to merge 3 commits into
labring:mainfrom
aimeritething:feat/credits-info-credits-list
Open

feat(account): expose per-grant credit details in credits/info#7280
aimeritething wants to merge 3 commits into
labring:mainfrom
aimeritething:feat/credits-info-credits-list

Conversation

@aimeritething

Copy link
Copy Markdown
Member

Problem

POST /payment/v1alpha1/credits/info only reports aggregate totals, so no user-facing endpoint exposes when a gift credit grant expires — even though every Credits row carries expire_at, and the handler already loads those rows before discarding the field during aggregation.

Ref: labring/sealos-private#117

Change

Add a creditsList array to the credits/info response, carrying each available credit grant's amount, usedAmount, startAt, expireAt, and status:

  • Additive only — all existing fields are unchanged; zero extra DB queries (the rows were already fetched).
  • Consistent with the aggregates — the list holds exactly the rows the totals are summed from (exhausted rows included), so sum(amount) == credits and sum(usedAmount) == deductionCredits always hold. Display layers filter with amount > usedAmount.
  • Clean serialization — zero times serialize as null, an empty result as []; internal row IDs and plan UUIDs are not exposed.

Also:

  • extracted the aggregation into a pure buildCreditsInfo function and added DB-free unit tests (multi-row accounting, the Free-plan KYC-pair copy, empty-list serialization);
  • fixed the swagger route comment to the actually registered /payment/v1alpha1 path.

Testing

go build ./... and go test ./api/ -run Test_buildCreditsInfo pass; the pre-existing DB-backed integration test is untouched.

🤖 Generated with Claude Code

https://claude.ai/code/session_01LVAx6Vw5dDgMzxpaj82qV3

The credits/info response only reported aggregate totals, so no user-facing
endpoint exposed gift credit expiry. Add a creditsList array carrying each
available credit grant's amount, usedAmount, startAt, expireAt, and status.

The list holds exactly the rows the aggregates are summed from (exhausted
rows included), so sum(amount) == credits and sum(usedAmount) ==
deductionCredits always hold. Zero times serialize as null; an empty result
serializes as []. Internal row IDs and plan UUIDs are not exposed.

Also extract the aggregation into a pure buildCreditsInfo function with
DB-free unit tests, and fix the swagger route comment to the registered
/payment/v1alpha1 path.

Ref: labring/sealos-private#117

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LVAx6Vw5dDgMzxpaj82qV3

Copilot AI 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.

Pull request overview

Adds per-grant credit details to the account service’s credits response.

Changes:

  • Adds creditsList with amounts, dates, and status.
  • Extracts aggregation logic and adds unit tests.
  • Corrects the source Swagger route annotation.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
service/account/api/credits.go Builds and returns per-grant credit details.
service/account/api/credits_test.go Tests aggregation and serialization behavior.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

// @Param req body CreditsInfoReq true "CreditsInfoReq"
// @Success 200 {object} CreditsInfoResp
// @Router /account/v1alpha1/credits/info [post]
// @Router /payment/v1alpha1/credits/info [post]
…docs

Address review feedback on labring#7280: the /credits/info annotation referenced
an undefined CreditsInfoResp and the served swagger was never regenerated.

- rename misnamed CreditsInfoReq to CreditsInfo (it is the response
  payload), add a typed CreditsInfoResp wrapper and return it from the
  handler instead of an ad-hoc gin.H (wire format unchanged)
- annotate the request body as helper.AuthBase, which is what the
  handler actually binds
- fix pre-existing annotations across the service that referenced
  non-existent types (blocking swag generation): prefix helper. where
  the type exists, otherwise use the actually-bound request type and
  gin.H responses
- regenerate docs with swag v1.16.2 (go.mod version) using
  --parseDependency; /payment/v1alpha1/credits/info and creditsList are
  now documented

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LVAx6Vw5dDgMzxpaj82qV3
@pull-request-size

Copy link
Copy Markdown

Whoa! Easy there, Partner!

This PR is too big. Please break it up into smaller PRs.

…ibvars lint

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016VxH9rUUwT7FEcqLVboNJj
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants