feat(account): expose per-grant credit details in credits/info - #7280
Open
aimeritething wants to merge 3 commits into
Open
feat(account): expose per-grant credit details in credits/info#7280aimeritething wants to merge 3 commits into
aimeritething wants to merge 3 commits into
Conversation
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
Contributor
There was a problem hiding this comment.
Pull request overview
Adds per-grant credit details to the account service’s credits response.
Changes:
- Adds
creditsListwith 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
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
POST /payment/v1alpha1/credits/infoonly reports aggregate totals, so no user-facing endpoint exposes when a gift credit grant expires — even though everyCreditsrow carriesexpire_at, and the handler already loads those rows before discarding the field during aggregation.Ref: labring/sealos-private#117
Change
Add a
creditsListarray to thecredits/inforesponse, carrying each available credit grant'samount,usedAmount,startAt,expireAt, andstatus:sum(amount) == creditsandsum(usedAmount) == deductionCreditsalways hold. Display layers filter withamount > usedAmount.null, an empty result as[]; internal row IDs and plan UUIDs are not exposed.Also:
buildCreditsInfofunction and added DB-free unit tests (multi-row accounting, the Free-plan KYC-pair copy, empty-list serialization);/payment/v1alpha1path.Testing
go build ./...andgo test ./api/ -run Test_buildCreditsInfopass; the pre-existing DB-backed integration test is untouched.🤖 Generated with Claude Code
https://claude.ai/code/session_01LVAx6Vw5dDgMzxpaj82qV3