first commit
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
package v1
|
||||
|
||||
import (
|
||||
"git.lzcwy.cn/zhengchiliu/zt-closet-manage-backend/internal/dto"
|
||||
"git.lzcwy.cn/zhengchiliu/zt-closet-manage-backend/internal/service"
|
||||
"git.lzcwy.cn/zhengchiliu/zt-closet-manage-backend/pkg/app"
|
||||
"git.lzcwy.cn/zhengchiliu/zt-closet-manage-backend/pkg/errcode"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// DashboardHandler 仪表盘统计接口。
|
||||
type DashboardHandler struct {
|
||||
svc *service.DashboardService
|
||||
}
|
||||
|
||||
// NewDashboardHandler 创建仪表盘 handler。
|
||||
func NewDashboardHandler() *DashboardHandler {
|
||||
return &DashboardHandler{svc: service.NewDashboardService()}
|
||||
}
|
||||
|
||||
// Summary 仪表盘核心指标。
|
||||
func (h *DashboardHandler) Summary(c *gin.Context) {
|
||||
response := app.NewResponse(c)
|
||||
out, e := h.svc.Summary(c.Request.Context())
|
||||
if e != nil {
|
||||
response.ToErrorResponse(e)
|
||||
return
|
||||
}
|
||||
response.ToResponse(out)
|
||||
}
|
||||
|
||||
// Trend 近 N 天趋势。
|
||||
func (h *DashboardHandler) Trend(c *gin.Context) {
|
||||
response := app.NewResponse(c)
|
||||
var request dto.TrendRequest
|
||||
if err := c.ShouldBindQuery(&request); err != nil {
|
||||
response.ToErrorResponse(errcode.InvalidParams.WithDetails(err.Error()))
|
||||
return
|
||||
}
|
||||
out, e := h.svc.Trends(c.Request.Context(), request.Days)
|
||||
if e != nil {
|
||||
response.ToErrorResponse(e)
|
||||
return
|
||||
}
|
||||
response.ToResponse(out)
|
||||
}
|
||||
Reference in New Issue
Block a user