Files
digital-psychology/apps/api/internal/handler/admin_report_template.go
T
jackyu66git 5de9a7bbe5 feat(ECR-038): GrowthInsights ReportTemplate 只读并 Closed
ReportTemplate catalog (000039) · Loop continuous.
2026-08-08 03:16:57 +08:00

47 lines
1.4 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) registerReportTemplates(authed *gin.RouterGroup) {
g := authed.Group("/growth")
g.GET("/report-templates", middleware.RequireAdminPermission(h.Svc, admin.PermGrowthRead), h.ListReportTemplates)
g.GET("/report-templates/:id", middleware.RequireAdminPermission(h.Svc, admin.PermGrowthRead), h.GetReportTemplate)
}
func (h *AdminHandler) ListReportTemplates(c *gin.Context) {
items, err := h.Svc.ListReportTemplates(c.Request.Context())
if err != nil {
response.Fail(c, http.StatusInternalServerError, 50050, "list report-template failed")
return
}
response.OK(c, gin.H{"items": items})
}
func (h *AdminHandler) GetReportTemplate(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.GetReportTemplate(c.Request.Context(), id)
if errors.Is(err, admin.ErrReportTemplateNotFound) {
response.Fail(c, http.StatusNotFound, 40420, "report-template not found")
return
}
if err != nil {
response.Fail(c, http.StatusInternalServerError, 50051, "get report-template failed")
return
}
response.OK(c, row)
}