feat(ECR-012–016): 合规、题库、时辰刷新、头像、MBTI OEJTS 与埋点
落地输入合规、探索题库、报告日/时辰刷新、账号头像、OEJTS 量表,并补齐 H5 埋点与 Admin 漏斗;同步 ESS 工件、切至自建 Git、清理 GitHub Actions。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -19,10 +20,33 @@ type ScaleHandler struct {
|
||||
// Register mounts routes.
|
||||
func (h *ScaleHandler) Register(rg *gin.RouterGroup) {
|
||||
rg.GET("/scales", h.List)
|
||||
rg.GET("/scale-bank/catalog", h.BankCatalog)
|
||||
rg.GET("/scale-bank/categories/:key", h.BankCategory)
|
||||
rg.GET("/scales/:slug", h.Get)
|
||||
rg.GET("/scales/:slug/result", h.LatestResult)
|
||||
rg.POST("/scales/:slug/result", h.Submit)
|
||||
}
|
||||
|
||||
// BankCatalog handles GET /scale-bank/catalog.
|
||||
func (h *ScaleHandler) BankCatalog(c *gin.Context) {
|
||||
out, err := h.Svc.BankCatalog()
|
||||
if err != nil {
|
||||
response.Fail(c, http.StatusInternalServerError, 50003, "bank catalog failed")
|
||||
return
|
||||
}
|
||||
response.OK(c, out)
|
||||
}
|
||||
|
||||
// BankCategory handles GET /scale-bank/categories/:key.
|
||||
func (h *ScaleHandler) BankCategory(c *gin.Context) {
|
||||
cat, items, err := h.Svc.BankCategory(c.Param("key"))
|
||||
if err != nil {
|
||||
response.Fail(c, http.StatusNotFound, 40402, "category not found")
|
||||
return
|
||||
}
|
||||
response.OK(c, gin.H{"category": cat, "items": items})
|
||||
}
|
||||
|
||||
// List handles GET /scales.
|
||||
func (h *ScaleHandler) List(c *gin.Context) {
|
||||
items, err := h.Svc.List(c.Request.Context())
|
||||
@@ -35,7 +59,8 @@ func (h *ScaleHandler) List(c *gin.Context) {
|
||||
|
||||
// Get handles GET /scales/:slug.
|
||||
func (h *ScaleHandler) Get(c *gin.Context) {
|
||||
d, err := h.Svc.Get(c.Request.Context(), c.Param("slug"))
|
||||
userID, _ := middleware.UserIDFromContext(c)
|
||||
d, err := h.Svc.Get(c.Request.Context(), userID, c.Param("slug"))
|
||||
if err != nil {
|
||||
response.Fail(c, http.StatusNotFound, 40402, err.Error())
|
||||
return
|
||||
@@ -43,6 +68,25 @@ func (h *ScaleHandler) Get(c *gin.Context) {
|
||||
response.OK(c, d)
|
||||
}
|
||||
|
||||
// LatestResult handles GET /scales/:slug/result.
|
||||
func (h *ScaleHandler) LatestResult(c *gin.Context) {
|
||||
userID, ok := middleware.UserIDFromContext(c)
|
||||
if !ok {
|
||||
response.Fail(c, http.StatusUnauthorized, 40100, "unauthorized")
|
||||
return
|
||||
}
|
||||
out, err := h.Svc.LatestResult(c.Request.Context(), userID, c.Param("slug"))
|
||||
if err != nil {
|
||||
if err.Error() == "scale not found" {
|
||||
response.Fail(c, http.StatusNotFound, 40402, err.Error())
|
||||
return
|
||||
}
|
||||
response.Fail(c, http.StatusNotFound, 40411, "result not found")
|
||||
return
|
||||
}
|
||||
response.OK(c, out)
|
||||
}
|
||||
|
||||
// Submit handles POST /scales/:slug/result.
|
||||
func (h *ScaleHandler) Submit(c *gin.Context) {
|
||||
userID, ok := middleware.UserIDFromContext(c)
|
||||
@@ -67,6 +111,10 @@ func (h *ScaleHandler) Submit(c *gin.Context) {
|
||||
ProfileID: pid, Answers: req.Answers,
|
||||
})
|
||||
if err != nil {
|
||||
if errors.Is(err, scale.ErrMembershipRequired) {
|
||||
response.Fail(c, http.StatusForbidden, 40310, "需要成长会员")
|
||||
return
|
||||
}
|
||||
response.Fail(c, http.StatusBadRequest, 30006, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user