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) registerHandoffCases(authed *gin.RouterGroup) { g := authed.Group("/ask") g.GET("/handoffs", middleware.RequireAdminPermission(h.Svc, admin.PermAskRead), h.ListHandoffCases) g.GET("/handoffs/:id", middleware.RequireAdminPermission(h.Svc, admin.PermAskRead), h.GetHandoffCase) } func (h *AdminHandler) ListHandoffCases(c *gin.Context) { items, err := h.Svc.ListHandoffCases(c.Request.Context()) if err != nil { response.Fail(c, http.StatusInternalServerError, 50050, "list handoff-case failed") return } response.OK(c, gin.H{"items": items}) } func (h *AdminHandler) GetHandoffCase(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.GetHandoffCase(c.Request.Context(), id) if errors.Is(err, admin.ErrHandoffCaseNotFound) { response.Fail(c, http.StatusNotFound, 40420, "handoff-case not found") return } if err != nil { response.Fail(c, http.StatusInternalServerError, 50051, "get handoff-case failed") return } response.OK(c, row) }