feat(ECR-030): ContentSafety ModerationCase 只读并 Closed
ModerationCase catalog (000031) · Loop continuous.
This commit is contained in:
@@ -58,6 +58,7 @@ func (h *AdminHandler) Register(api *gin.RouterGroup) {
|
||||
h.registerKnowledgeChunks(authed)
|
||||
h.registerToolDefinitions(authed)
|
||||
h.registerBlockPolicies(authed)
|
||||
h.registerModerationCases(authed)
|
||||
}
|
||||
|
||||
func (h *AdminHandler) Login(c *gin.Context) {
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
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) registerModerationCases(authed *gin.RouterGroup) {
|
||||
g := authed.Group("/content-safety")
|
||||
g.GET("/cases", middleware.RequireAdminPermission(h.Svc, admin.PermContentSafetyRead), h.ListModerationCases)
|
||||
g.GET("/cases/:id", middleware.RequireAdminPermission(h.Svc, admin.PermContentSafetyRead), h.GetModerationCase)
|
||||
}
|
||||
|
||||
func (h *AdminHandler) ListModerationCases(c *gin.Context) {
|
||||
items, err := h.Svc.ListModerationCases(c.Request.Context())
|
||||
if err != nil {
|
||||
response.Fail(c, http.StatusInternalServerError, 50050, "list moderation-case failed")
|
||||
return
|
||||
}
|
||||
response.OK(c, gin.H{"items": items})
|
||||
}
|
||||
|
||||
func (h *AdminHandler) GetModerationCase(c *gin.Context) {
|
||||
id, err := uuid.Parse(c.Param("id"))
|
||||
if err != nil {
|
||||
response.Fail(c, http.StatusBadRequest, 40002, "invalid id")
|
||||
return
|
||||
}
|
||||
row, err := h.Svc.GetModerationCase(c.Request.Context(), id)
|
||||
if errors.Is(err, admin.ErrModerationCaseNotFound) {
|
||||
response.Fail(c, http.StatusNotFound, 40420, "moderation-case not found")
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
response.Fail(c, http.StatusInternalServerError, 50051, "get moderation-case failed")
|
||||
return
|
||||
}
|
||||
response.OK(c, row)
|
||||
}
|
||||
Reference in New Issue
Block a user