- 新增删除按钮(带二次确认)到账单详情抽屉 - 后端实现软删除(设置 is_deleted 标记) - 所有查询方法自动过滤已删除记录 - 账单列表和复核页面都支持删除 - 版本更新至 1.2.0
79 lines
1.6 KiB
Go
79 lines
1.6 KiB
Go
// Package router 路由配置
|
|
package router
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
"billai-server/handler"
|
|
"billai-server/middleware"
|
|
)
|
|
|
|
// Config 路由配置参数
|
|
type Config struct {
|
|
OutputDir string // 输出目录(用于静态文件服务)
|
|
Version string // 应用版本
|
|
}
|
|
|
|
// Setup 设置所有路由
|
|
func Setup(r *gin.Engine, cfg Config) {
|
|
// 健康检查
|
|
r.GET("/health", healthCheck(cfg.Version))
|
|
|
|
// API 路由组
|
|
setupAPIRoutes(r)
|
|
|
|
// 静态文件下载
|
|
r.Static("/download", cfg.OutputDir)
|
|
}
|
|
|
|
// healthCheck 健康检查处理器
|
|
func healthCheck(version string) gin.HandlerFunc {
|
|
return func(c *gin.Context) {
|
|
c.JSON(http.StatusOK, gin.H{
|
|
"status": "ok",
|
|
"version": version,
|
|
})
|
|
}
|
|
}
|
|
|
|
// setupAPIRoutes 设置 API 路由
|
|
func setupAPIRoutes(r *gin.Engine) {
|
|
api := r.Group("/api")
|
|
{
|
|
// 认证相关(无需登录)
|
|
api.POST("/auth/login", handler.Login)
|
|
api.GET("/auth/validate", handler.ValidateToken)
|
|
|
|
// 需要登录的 API
|
|
authed := api.Group("/")
|
|
authed.Use(middleware.AuthRequired())
|
|
{
|
|
// 账单上传
|
|
authed.POST("/upload", handler.Upload)
|
|
|
|
// 复核相关
|
|
authed.GET("/review", handler.Review)
|
|
|
|
// 账单查询
|
|
authed.GET("/bills", handler.ListBills)
|
|
|
|
// 编辑账单
|
|
authed.POST("/bills/:id", handler.UpdateBill)
|
|
|
|
// 删除账单(软删除)
|
|
authed.DELETE("/bills/:id", handler.DeleteBill)
|
|
|
|
// 手动创建账单
|
|
authed.POST("/bills/manual", handler.CreateManualBills)
|
|
|
|
// 月度统计(全部数据)
|
|
authed.GET("/monthly-stats", handler.MonthlyStats)
|
|
|
|
// 待复核数据统计
|
|
authed.GET("/review-stats", handler.ReviewStats)
|
|
}
|
|
}
|
|
}
|