每账号仅一条 self(migration 40902);合盘只选 TA;账号昵称可改;首页穿衣/颜色/养生贴士。 Co-authored-by: Cursor <cursoragent@cursor.com>
47 lines
1.2 KiB
Go
47 lines
1.2 KiB
Go
package handler
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
"github.com/yuxingu/digital-psychology/apps/api/internal/middleware"
|
|
"github.com/yuxingu/digital-psychology/apps/api/internal/repository"
|
|
"github.com/yuxingu/digital-psychology/apps/api/internal/service/home"
|
|
"github.com/yuxingu/digital-psychology/apps/api/pkg/response"
|
|
)
|
|
|
|
// HomeHandler serves GET /api/v1/home/* (DeviceAuth).
|
|
type HomeHandler struct {
|
|
Svc *home.Service
|
|
}
|
|
|
|
// Register mounts home routes.
|
|
func (h *HomeHandler) Register(api *gin.RouterGroup) {
|
|
g := api.Group("/home")
|
|
g.GET("/tools", h.Tools)
|
|
g.GET("/daily-tips", h.DailyTips)
|
|
}
|
|
|
|
func (h *HomeHandler) Tools(c *gin.Context) {
|
|
items, err := h.Svc.ListPublic(c.Request.Context())
|
|
if err != nil {
|
|
response.Fail(c, http.StatusInternalServerError, 50030, "home tools failed")
|
|
return
|
|
}
|
|
if items == nil {
|
|
items = []repository.HomeTool{}
|
|
}
|
|
response.OK(c, gin.H{"items": items})
|
|
}
|
|
|
|
func (h *HomeHandler) DailyTips(c *gin.Context) {
|
|
uid, _ := middleware.UserIDFromContext(c)
|
|
tips, err := h.Svc.DailyTips(c.Request.Context(), uid)
|
|
if err != nil {
|
|
response.Fail(c, http.StatusInternalServerError, 50031, "daily tips failed")
|
|
return
|
|
}
|
|
response.OK(c, tips)
|
|
}
|