36 lines
953 B
Go
36 lines
953 B
Go
package v1
|
|
|
|
import (
|
|
"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"
|
|
)
|
|
|
|
// HoroscopeHandler 今日运势接口。
|
|
type HoroscopeHandler struct {
|
|
svc *service.HoroscopeService
|
|
}
|
|
|
|
// NewHoroscopeHandler 创建运势 handler。
|
|
func NewHoroscopeHandler() *HoroscopeHandler {
|
|
return &HoroscopeHandler{svc: service.NewHoroscopeService()}
|
|
}
|
|
|
|
// Today 获取当前用户今日运势。
|
|
func (h *HoroscopeHandler) Today(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.GetToday(c.Request.Context(), userID)
|
|
if e != nil {
|
|
response.ToErrorResponse(e)
|
|
return
|
|
}
|
|
response.ToResponse(out)
|
|
}
|