feat(ECR-045): ImageCardDeck 写面闭环并 Closed
复用 admin.explore.write、POST/PUT+审计、C端 GET /cards/decks、 H5 无 active 空态/失败回退;migration 000054。无牌面内容编辑。 ExploreConfig Loop STOP,禁自动 ECR-046。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -16,6 +16,8 @@ func (h *AdminHandler) registerImageCardDecks(authed *gin.RouterGroup) {
|
||||
g := authed.Group("/explore")
|
||||
g.GET("/image-card-decks", middleware.RequireAdminPermission(h.Svc, admin.PermExploreRead), h.ListImageCardDecks)
|
||||
g.GET("/image-card-decks/:id", middleware.RequireAdminPermission(h.Svc, admin.PermExploreRead), h.GetImageCardDeck)
|
||||
g.POST("/image-card-decks", middleware.RequireAdminPermission(h.Svc, admin.PermExploreWrite), h.CreateImageCardDeck)
|
||||
g.PUT("/image-card-decks/:id", middleware.RequireAdminPermission(h.Svc, admin.PermExploreWrite), h.UpdateImageCardDeck)
|
||||
}
|
||||
|
||||
func (h *AdminHandler) ListImageCardDecks(c *gin.Context) {
|
||||
@@ -44,3 +46,66 @@ func (h *AdminHandler) GetImageCardDeck(c *gin.Context) {
|
||||
}
|
||||
response.OK(c, row)
|
||||
}
|
||||
|
||||
func (h *AdminHandler) CreateImageCardDeck(c *gin.Context) {
|
||||
adminID, ok := middleware.AdminIDFromContext(c)
|
||||
if !ok {
|
||||
response.Fail(c, http.StatusUnauthorized, 40101, "admin auth required")
|
||||
return
|
||||
}
|
||||
var body admin.ImageCardDeckWriteBody
|
||||
if err := c.ShouldBindJSON(&body); err != nil {
|
||||
response.Fail(c, http.StatusBadRequest, 40054, "invalid body")
|
||||
return
|
||||
}
|
||||
row, err := h.Svc.CreateImageCardDeck(c.Request.Context(), adminID, body)
|
||||
if errors.Is(err, admin.ErrInvalidImageCardDeck) {
|
||||
response.Fail(c, http.StatusBadRequest, 40055, "invalid image card deck")
|
||||
return
|
||||
}
|
||||
if errors.Is(err, admin.ErrImageCardDeckConflict) {
|
||||
response.Fail(c, http.StatusConflict, 40912, "image card deck code conflict")
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
response.Fail(c, http.StatusInternalServerError, 50052, "create image card deck failed")
|
||||
return
|
||||
}
|
||||
response.OK(c, row)
|
||||
}
|
||||
|
||||
func (h *AdminHandler) UpdateImageCardDeck(c *gin.Context) {
|
||||
adminID, ok := middleware.AdminIDFromContext(c)
|
||||
if !ok {
|
||||
response.Fail(c, http.StatusUnauthorized, 40101, "admin auth required")
|
||||
return
|
||||
}
|
||||
id, err := uuid.Parse(c.Param("id"))
|
||||
if err != nil {
|
||||
response.Fail(c, http.StatusBadRequest, 40002, "invalid id")
|
||||
return
|
||||
}
|
||||
var body admin.ImageCardDeckWriteBody
|
||||
if err := c.ShouldBindJSON(&body); err != nil {
|
||||
response.Fail(c, http.StatusBadRequest, 40054, "invalid body")
|
||||
return
|
||||
}
|
||||
row, err := h.Svc.UpdateImageCardDeck(c.Request.Context(), adminID, id, body)
|
||||
if errors.Is(err, admin.ErrImageCardDeckNotFound) {
|
||||
response.Fail(c, http.StatusNotFound, 40420, "image-card-deck not found")
|
||||
return
|
||||
}
|
||||
if errors.Is(err, admin.ErrInvalidImageCardDeck) {
|
||||
response.Fail(c, http.StatusBadRequest, 40055, "invalid image card deck")
|
||||
return
|
||||
}
|
||||
if errors.Is(err, admin.ErrImageCardDeckConflict) {
|
||||
response.Fail(c, http.StatusConflict, 40912, "image card deck code conflict")
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
response.Fail(c, http.StatusInternalServerError, 50053, "update image card deck failed")
|
||||
return
|
||||
}
|
||||
response.OK(c, row)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
"github.com/yuxingu/digital-psychology/apps/api/internal/repository"
|
||||
"github.com/yuxingu/digital-psychology/apps/api/pkg/response"
|
||||
)
|
||||
|
||||
// ImageCardDeckPublicHandler serves GET /api/v1/cards/decks (DeviceAuth).
|
||||
type ImageCardDeckPublicHandler struct {
|
||||
Repo *repository.AdminRepo
|
||||
}
|
||||
|
||||
// Register mounts public image card deck routes.
|
||||
func (h *ImageCardDeckPublicHandler) Register(api *gin.RouterGroup) {
|
||||
api.GET("/cards/decks", h.ListActive)
|
||||
}
|
||||
|
||||
func (h *ImageCardDeckPublicHandler) ListActive(c *gin.Context) {
|
||||
if h.Repo == nil {
|
||||
response.OK(c, gin.H{"items": []repository.ImageCardDeckRow{}})
|
||||
return
|
||||
}
|
||||
items, err := h.Repo.ListActiveImageCardDecks(c.Request.Context())
|
||||
if err != nil {
|
||||
response.Fail(c, http.StatusInternalServerError, 50054, "card decks failed")
|
||||
return
|
||||
}
|
||||
if items == nil {
|
||||
items = []repository.ImageCardDeckRow{}
|
||||
}
|
||||
response.OK(c, gin.H{"items": items})
|
||||
}
|
||||
Reference in New Issue
Block a user