47 lines
1.4 KiB
Go
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) registerStarConfigs(authed *gin.RouterGroup) {
|
|
g := authed.Group("/explore")
|
|
g.GET("/star-configs", middleware.RequireAdminPermission(h.Svc, admin.PermExploreRead), h.ListStarConfigs)
|
|
g.GET("/star-configs/:id", middleware.RequireAdminPermission(h.Svc, admin.PermExploreRead), h.GetStarConfig)
|
|
}
|
|
|
|
func (h *AdminHandler) ListStarConfigs(c *gin.Context) {
|
|
items, err := h.Svc.ListStarConfigs(c.Request.Context())
|
|
if err != nil {
|
|
response.Fail(c, http.StatusInternalServerError, 50050, "list star-config failed")
|
|
return
|
|
}
|
|
response.OK(c, gin.H{"items": items})
|
|
}
|
|
|
|
func (h *AdminHandler) GetStarConfig(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.GetStarConfig(c.Request.Context(), id)
|
|
if errors.Is(err, admin.ErrStarConfigNotFound) {
|
|
response.Fail(c, http.StatusNotFound, 40420, "star-config not found")
|
|
return
|
|
}
|
|
if err != nil {
|
|
response.Fail(c, http.StatusInternalServerError, 50051, "get star-config failed")
|
|
return
|
|
}
|
|
response.OK(c, row)
|
|
}
|