美化排版前端管理后台
This commit is contained in:
@@ -22,6 +22,36 @@ func NewAdminHandler(store *storage.ProductStore, cfg *config.Config, siteStore
|
||||
return &AdminHandler{store: store, cfg: cfg, siteStore: siteStore, orderStore: orderStore, chatStore: chatStore}
|
||||
}
|
||||
|
||||
// GetAnnouncement 公开获取公告内容。
|
||||
func (h *AdminHandler) GetAnnouncement(c *gin.Context) {
|
||||
ann, err := h.siteStore.GetAnnouncement()
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"data": ann})
|
||||
}
|
||||
|
||||
// SetAnnouncement 管理员更新公告内容。
|
||||
func (h *AdminHandler) SetAnnouncement(c *gin.Context) {
|
||||
if !h.requireAdmin(c) {
|
||||
return
|
||||
}
|
||||
var payload struct {
|
||||
Content string `json:"content"`
|
||||
}
|
||||
if err := c.ShouldBindJSON(&payload); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "invalid body"})
|
||||
return
|
||||
}
|
||||
if err := h.siteStore.SetAnnouncement(payload.Content); err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
ann, _ := h.siteStore.GetAnnouncement()
|
||||
c.JSON(http.StatusOK, gin.H{"data": ann})
|
||||
}
|
||||
|
||||
// requireAdmin 校验管理员令牌。
|
||||
// 优先级:X-Admin-Token 请求头 > Authorization 请求头 > ?token 查询参数(旧版兼容)。
|
||||
func (h *AdminHandler) requireAdmin(c *gin.Context) bool {
|
||||
|
||||
Reference in New Issue
Block a user