feat: add balance and ledger endpoints for tenant
- Implemented MyBalance and MyLedgerPage methods in the ledger service to retrieve current user balance and transaction history for a specified tenant. - Added corresponding test cases for MyBalance and MyLedgerPage methods in the ledger test suite. - Created DTOs for balance response and ledger items to structure the response data. - Updated Swagger documentation to include new endpoints for retrieving tenant balance and ledgers. - Added HTTP tests for the new endpoints to ensure proper functionality.
This commit is contained in:
@@ -2,7 +2,10 @@ package tenant
|
||||
|
||||
import (
|
||||
"quyun/v2/app/http/tenant/dto"
|
||||
"quyun/v2/app/requests"
|
||||
"quyun/v2/app/services"
|
||||
"quyun/v2/database/models"
|
||||
"quyun/v2/pkg/consts"
|
||||
|
||||
"github.com/gofiber/fiber/v3"
|
||||
)
|
||||
@@ -32,3 +35,45 @@ func (*me) get(ctx fiber.Ctx, tenant *models.Tenant, user *models.User, tenantUs
|
||||
TenantUser: tenantUser,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// balance
|
||||
//
|
||||
// @Summary 当前租户余额信息
|
||||
// @Tags Tenant
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param tenantCode path string true "Tenant Code"
|
||||
// @Success 200 {object} dto.MeBalanceResponse
|
||||
//
|
||||
// @Router /t/:tenantCode/v1/me/balance [get]
|
||||
// @Bind tenant local key(tenant)
|
||||
// @Bind user local key(user)
|
||||
func (*me) balance(ctx fiber.Ctx, tenant *models.Tenant, user *models.User) (*dto.MeBalanceResponse, error) {
|
||||
m, err := services.Ledger.MyBalance(ctx.Context(), tenant.ID, user.ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &dto.MeBalanceResponse{
|
||||
Currency: consts.CurrencyCNY,
|
||||
Balance: m.Balance,
|
||||
BalanceFrozen: m.BalanceFrozen,
|
||||
UpdatedAt: m.UpdatedAt,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// ledgers
|
||||
//
|
||||
// @Summary 当前租户余额流水(分页)
|
||||
// @Tags Tenant
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param tenantCode path string true "Tenant Code"
|
||||
// @Success 200 {object} requests.Pager{items=dto.MyLedgerItem}
|
||||
//
|
||||
// @Router /t/:tenantCode/v1/me/ledgers [get]
|
||||
// @Bind tenant local key(tenant)
|
||||
// @Bind user local key(user)
|
||||
// @Bind filter query
|
||||
func (*me) ledgers(ctx fiber.Ctx, tenant *models.Tenant, user *models.User, filter *dto.MyLedgerListFilter) (*requests.Pager, error) {
|
||||
return services.Ledger.MyLedgerPage(ctx.Context(), tenant.ID, user.ID, filter)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user