新增 admin.ask.read、GET /admin/ask/threads*(AskSessionView)与 admin-h5「问答」页;禁改消息/UGC/真支付。 Co-authored-by: Cursor <cursoragent@cursor.com>
58 lines
1.7 KiB
Go
58 lines
1.7 KiB
Go
package handler
|
|
|
|
import (
|
|
"errors"
|
|
"net/http"
|
|
"strconv"
|
|
|
|
"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) registerAskOps(authed *gin.RouterGroup) {
|
|
authed.GET("/ask/threads", middleware.RequireAdminPermission(h.Svc, admin.PermAskRead), h.ListAskThreads)
|
|
authed.GET("/ask/threads/:id", middleware.RequireAdminPermission(h.Svc, admin.PermAskRead), h.GetAskThread)
|
|
}
|
|
|
|
func (h *AdminHandler) ListAskThreads(c *gin.Context) {
|
|
limit, _ := strconv.Atoi(c.DefaultQuery("limit", "20"))
|
|
offset, _ := strconv.Atoi(c.DefaultQuery("offset", "0"))
|
|
var userID *uuid.UUID
|
|
if q := c.Query("user_id"); q != "" {
|
|
id, err := uuid.Parse(q)
|
|
if err != nil {
|
|
response.Fail(c, http.StatusBadRequest, 40002, "invalid user_id")
|
|
return
|
|
}
|
|
userID = &id
|
|
}
|
|
items, err := h.Svc.ListAskSessions(c.Request.Context(), userID, limit, offset)
|
|
if err != nil {
|
|
response.Fail(c, http.StatusInternalServerError, 50019, "list ask threads failed")
|
|
return
|
|
}
|
|
response.OK(c, gin.H{"items": items})
|
|
}
|
|
|
|
func (h *AdminHandler) GetAskThread(c *gin.Context) {
|
|
id, err := uuid.Parse(c.Param("id"))
|
|
if err != nil {
|
|
response.Fail(c, http.StatusBadRequest, 40002, "invalid thread id")
|
|
return
|
|
}
|
|
detail, err := h.Svc.GetAskSessionDetail(c.Request.Context(), id)
|
|
if errors.Is(err, admin.ErrAskThreadNotFound) {
|
|
response.Fail(c, http.StatusNotFound, 40402, "ask thread not found")
|
|
return
|
|
}
|
|
if err != nil {
|
|
response.Fail(c, http.StatusInternalServerError, 50020, "get ask thread failed")
|
|
return
|
|
}
|
|
response.OK(c, detail)
|
|
}
|