## 功能概述 在钱包旁边新增公告中心,用户可以查看平台通知、教程、规则和常见问题。 ## 主要变更 ### 后端 - 新增 announcement 模块(handler/service/repository) - 新增 announcements 数据库表 - 添加公告相关 API 端点(用户端和管理端) - 扩展 response 包,新增 NotFound 和 InternalServerError 方法 ### 前端 - 新增公告功能模块(/features/announcement) - 实现公告列表页和详情页 - 在顶部导航添加公告入口(钱包旁边) - 支持按分类筛选(通知、教程、规则、FAQ) - 支持置顶和重要标记显示 ### 数据库 - 迁移文件:000005_add_announcements.sql - 示例数据:000006_insert_sample_announcements.sql - 包含6条示例公告 ## 技术特点 - 遵循项目现有架构模式 - 响应式设计,支持移动端 - 自动统计浏览次数 - 支持富文本内容展示 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
57 lines
1.2 KiB
Go
57 lines
1.2 KiB
Go
package response
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
type Body struct {
|
|
Code string `json:"code"`
|
|
Message string `json:"message"`
|
|
Data any `json:"data,omitempty"`
|
|
}
|
|
|
|
func OK(c *gin.Context, data any) {
|
|
c.JSON(http.StatusOK, Body{
|
|
Code: "ok",
|
|
Message: "ok",
|
|
Data: data,
|
|
})
|
|
}
|
|
|
|
func Created(c *gin.Context, data any) {
|
|
c.JSON(http.StatusCreated, Body{
|
|
Code: "ok",
|
|
Message: "created",
|
|
Data: data,
|
|
})
|
|
}
|
|
|
|
func Error(c *gin.Context, status int, code, message string) {
|
|
c.JSON(status, Body{
|
|
Code: code,
|
|
Message: message,
|
|
})
|
|
}
|
|
|
|
func BadRequest(c *gin.Context, message string) {
|
|
Error(c, http.StatusBadRequest, "bad_request", message)
|
|
}
|
|
|
|
func Unauthorized(c *gin.Context, message string) {
|
|
Error(c, http.StatusUnauthorized, "unauthorized", message)
|
|
}
|
|
|
|
func ServiceUnavailable(c *gin.Context, message string) {
|
|
Error(c, http.StatusServiceUnavailable, "service_unavailable", message)
|
|
}
|
|
|
|
func NotFound(c *gin.Context, message string) {
|
|
Error(c, http.StatusNotFound, "not_found", message)
|
|
}
|
|
|
|
func InternalServerError(c *gin.Context, message string) {
|
|
Error(c, http.StatusInternalServerError, "internal_server_error", message)
|
|
}
|