聚合 GET /admin/users/:id/entitlements(Membership∪DeepAccess∪问答额度)与 admin-h5 权益 Tab;无 migration / 无真支付。 Co-authored-by: Cursor <cursoragent@cursor.com>
36 lines
1.0 KiB
Go
36 lines
1.0 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) registerEntitlement(authed *gin.RouterGroup) {
|
|
authed.GET("/users/:id/entitlements", middleware.RequireAdminPermission(h.Svc, admin.PermUsersRead), h.GetUserEntitlements)
|
|
}
|
|
|
|
func (h *AdminHandler) GetUserEntitlements(c *gin.Context) {
|
|
id, err := uuid.Parse(c.Param("id"))
|
|
if err != nil {
|
|
response.Fail(c, http.StatusBadRequest, 40002, "invalid user id")
|
|
return
|
|
}
|
|
ent, err := h.Svc.GetUserEntitlement(c.Request.Context(), id)
|
|
if errors.Is(err, admin.ErrUserNotFound) {
|
|
response.Fail(c, http.StatusNotFound, 40401, "user not found")
|
|
return
|
|
}
|
|
if err != nil {
|
|
response.Fail(c, http.StatusInternalServerError, 50021, "get entitlements failed")
|
|
return
|
|
}
|
|
response.OK(c, ent)
|
|
}
|