Credit Microservice
The Credit microservice handles user credit balances, transactions, and purchase records. It defines MongoDB-based models and exposes gRPC endpoints for managing credits and transactions in an application ecosystem.
Models (credit.go)β
Purchaseβ
Tracks purchases made by users using credits.
| Field | Type | Description |
|---|---|---|
ID | ObjectID | Unique identifier (MongoDB) |
UserID | uint32 | ID of the purchasing user |
AppID | uint32 | ID of the app where the purchase was made |
ReportID | string | ID of the report purchased |
ReportName | string | Name of the report |
Credits | uint32 | Number of credits used |
CreatedAt | time.Time | Timestamp of purchase |
CreatedBy | uint32 | ID of the user who recorded the purchase |
CreditTransactionβ
Represents a credit adjustment for a user.
| Field | Type | Description |
|---|---|---|
ID | ObjectID | Unique identifier (MongoDB) |
UserID | uint32 | User receiving or spending credits |
AppID | uint32 | Application context for the transaction |
Credits | uint32 | Amount of credits |
CreatedAt | time.Time | Timestamp of the transaction |
CreatedBy | uint32 | ID of the actor who performed the transaction |
Balanceβ
Tracks credit balance for a specific app.
| Field | Type | Description |
|---|---|---|
AppID | uint32 | Application ID |
Balance | uint32 | Available credit balance |
UserCreditsβ
Tracks credit balances across multiple apps for a user.
| Field | Type | Description |
|---|---|---|
ID | ObjectID | Unique identifier (MongoDB) |
UserID | uint32 | ID of the user |
Balances | []Balance | List of balances by app |
CreatedAt | time.Time | Record creation timestamp |
UpdatedAt | time.Time | Last update timestamp |
CreatedBy | uint32 | ID of creator |
UpdatedBy | uint32 | ID of last updater |
gRPC Service (credit.proto)β
The .proto file defines messages and RPC services for handling credit-related operations.
Messagesβ
Purchase,CreditTransaction,UserCredits,Balance: Reflect the Go model structures.CreditRequest: Request to add or consume credits.PurchaseRequest: Request to record a purchase.UserId,AppId: Used to fetch credit details by user/app.Empty: Placeholder for requests/responses that donβt require payload.
Servicesβ
AddCredits(CreditRequest) returns (Empty)UseCredits(PurchaseRequest) returns (Empty)GetUserCredits(UserId) returns (UserCredits)GetAppBalance(AppId) returns (Balance)ListUserPurchases(UserId) returns (stream Purchase)ListUserTransactions(UserId) returns (stream CreditTransaction)
These services allow managing credit distribution, purchases, and history tracking across users and apps.