58 lines
1.5 KiB
Go
58 lines
1.5 KiB
Go
package v1
|
|
|
|
import (
|
|
"git.lzcwy.cn/zhengchiliu/zt-closet-backend/internal/dto"
|
|
"git.lzcwy.cn/zhengchiliu/zt-closet-backend/internal/middleware"
|
|
"git.lzcwy.cn/zhengchiliu/zt-closet-backend/internal/service"
|
|
"git.lzcwy.cn/zhengchiliu/zt-closet-backend/pkg/app"
|
|
"git.lzcwy.cn/zhengchiliu/zt-closet-backend/pkg/errcode"
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
// QuotaHandler 额度相关接口。
|
|
type QuotaHandler struct {
|
|
svc *service.QuotaService
|
|
}
|
|
|
|
// NewQuotaHandler 创建额度 handler。
|
|
func NewQuotaHandler() *QuotaHandler {
|
|
return &QuotaHandler{svc: service.NewQuotaService()}
|
|
}
|
|
|
|
// Info 获取当前用户额度概览。
|
|
func (h *QuotaHandler) Info(c *gin.Context) {
|
|
response := app.NewResponse(c)
|
|
userID, ok := middleware.GetUserID(c.Request.Context())
|
|
if !ok {
|
|
response.ToErrorResponse(errcode.Unauthorized)
|
|
return
|
|
}
|
|
out, e := h.svc.InfoGetBySelf(c.Request.Context(), userID)
|
|
if e != nil {
|
|
response.ToErrorResponse(e)
|
|
return
|
|
}
|
|
response.ToResponse(out)
|
|
}
|
|
|
|
// FlowList 分页查询当前用户额度流水。
|
|
func (h *QuotaHandler) FlowList(c *gin.Context) {
|
|
response := app.NewResponse(c)
|
|
userID, ok := middleware.GetUserID(c.Request.Context())
|
|
if !ok {
|
|
response.ToErrorResponse(errcode.Unauthorized)
|
|
return
|
|
}
|
|
var request dto.QuotaFlowListRequest
|
|
if err := c.ShouldBindQuery(&request); err != nil {
|
|
response.ToErrorResponse(errcode.InvalidParams.WithDetails(err.Error()))
|
|
return
|
|
}
|
|
out, e := h.svc.FlowList(c.Request.Context(), userID, &request)
|
|
if e != nil {
|
|
response.ToErrorResponse(e)
|
|
return
|
|
}
|
|
response.ToResponse(out)
|
|
}
|