落地输入合规、探索题库、报告日/时辰刷新、账号头像、OEJTS 量表,并补齐 H5 埋点与 Admin 漏斗;同步 ESS 工件、切至自建 Git、清理 GitHub Actions。 Co-authored-by: Cursor <cursoragent@cursor.com>
53 lines
1.4 KiB
Go
53 lines
1.4 KiB
Go
package handler
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
"github.com/yuxingu/digital-psychology/apps/api/internal/explore"
|
|
"github.com/yuxingu/digital-psychology/apps/api/internal/service/scale"
|
|
"github.com/yuxingu/digital-psychology/apps/api/pkg/response"
|
|
)
|
|
|
|
// ExploreHandler serves the explore catalog.
|
|
type ExploreHandler struct {
|
|
Scales *scale.Service
|
|
}
|
|
|
|
// Register mounts explore routes.
|
|
func (h *ExploreHandler) Register(rg *gin.RouterGroup) {
|
|
rg.GET("/explore/catalog", h.Catalog)
|
|
rg.GET("/explore/catalog/:key", h.Category)
|
|
}
|
|
|
|
// Catalog handles GET /explore/catalog.
|
|
func (h *ExploreHandler) Catalog(c *gin.Context) {
|
|
cats := explore.Catalog()
|
|
if h.Scales != nil {
|
|
if items, err := h.Scales.List(c.Request.Context()); err == nil {
|
|
cats = explore.WithPublishedScales(cats, items)
|
|
}
|
|
}
|
|
response.OK(c, gin.H{"categories": cats})
|
|
}
|
|
|
|
// Category handles GET /explore/catalog/:key.
|
|
func (h *ExploreHandler) Category(c *gin.Context) {
|
|
cat := explore.CategoryByKey(c.Param("key"))
|
|
if cat == nil {
|
|
response.Fail(c, http.StatusNotFound, 40402, "category not found")
|
|
return
|
|
}
|
|
if cat.Key == "tests" && h.Scales != nil {
|
|
if items, err := h.Scales.List(c.Request.Context()); err == nil {
|
|
enriched := explore.WithPublishedScales([]explore.Category{*cat}, items)
|
|
if len(enriched) > 0 {
|
|
response.OK(c, enriched[0])
|
|
return
|
|
}
|
|
}
|
|
}
|
|
response.OK(c, cat)
|
|
}
|