聚合 GET /admin/users/:id/insight(报告类型/派生标签/行为快照),admin-h5 洞察 Tab;无 migration / 无 UGC / 无真支付。 Co-authored-by: Cursor <cursoragent@cursor.com>
36 lines
1008 B
Go
36 lines
1008 B
Go
package handler
|
|
|
|
import (
|
|
"errors"
|
|
"net/http"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/google/uuid"
|
|
|
|
"github.com/yuxingu/digital-psychology/apps/api/internal/middleware"
|
|
"github.com/yuxingu/digital-psychology/apps/api/internal/service/admin"
|
|
"github.com/yuxingu/digital-psychology/apps/api/pkg/response"
|
|
)
|
|
|
|
func (h *AdminHandler) registerInsight(authed *gin.RouterGroup) {
|
|
authed.GET("/users/:id/insight", middleware.RequireAdminPermission(h.Svc, admin.PermUsersRead), h.GetUserInsight)
|
|
}
|
|
|
|
func (h *AdminHandler) GetUserInsight(c *gin.Context) {
|
|
id, err := uuid.Parse(c.Param("id"))
|
|
if err != nil {
|
|
response.Fail(c, http.StatusBadRequest, 40002, "invalid user id")
|
|
return
|
|
}
|
|
insight, err := h.Svc.GetUserInsight(c.Request.Context(), id)
|
|
if errors.Is(err, admin.ErrUserNotFound) {
|
|
response.Fail(c, http.StatusNotFound, 40401, "user not found")
|
|
return
|
|
}
|
|
if err != nil {
|
|
response.Fail(c, http.StatusInternalServerError, 50018, "get insight failed")
|
|
return
|
|
}
|
|
response.OK(c, insight)
|
|
}
|