Files
digital-psychology/apps/api/internal/handler/admin_intervention_outcome.go
T
jackyu66git 447fb6da16 feat(ECR-032): CrisisCare InterventionOutcome 只读并 Closed
InterventionOutcome catalog (000033) · Loop continuous.
2026-08-08 03:15:30 +08:00

47 lines
1.5 KiB
Go

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) registerInterventionOutcomes(authed *gin.RouterGroup) {
g := authed.Group("/crisis")
g.GET("/interventions", middleware.RequireAdminPermission(h.Svc, admin.PermCrisisRead), h.ListInterventionOutcomes)
g.GET("/interventions/:id", middleware.RequireAdminPermission(h.Svc, admin.PermCrisisRead), h.GetInterventionOutcome)
}
func (h *AdminHandler) ListInterventionOutcomes(c *gin.Context) {
items, err := h.Svc.ListInterventionOutcomes(c.Request.Context())
if err != nil {
response.Fail(c, http.StatusInternalServerError, 50050, "list intervention-outcome failed")
return
}
response.OK(c, gin.H{"items": items})
}
func (h *AdminHandler) GetInterventionOutcome(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.GetInterventionOutcome(c.Request.Context(), id)
if errors.Is(err, admin.ErrInterventionOutcomeNotFound) {
response.Fail(c, http.StatusNotFound, 40420, "intervention-outcome not found")
return
}
if err != nil {
response.Fail(c, http.StatusInternalServerError, 50051, "get intervention-outcome failed")
return
}
response.OK(c, row)
}