feat: 完善项目架构并增强分析页面功能
- 新增项目文档和 Docker 配置 - 添加 README.md 和 TODO.md 项目文档 - 为各服务添加 Dockerfile 和 docker-compose 配置 - 重构后端架构 - 新增 adapter 层(HTTP/Python 适配器) - 新增 repository 层(数据访问抽象) - 新增 router 模块统一管理路由 - 新增账单处理 handler - 扩展前端 UI 组件库 - 新增 Calendar、DateRangePicker、Drawer、Popover 等组件 - 集成 shadcn-svelte 组件库 - 增强分析页面功能 - 添加时间范围筛选器(支持本月默认值) - 修复 DateRangePicker 默认值显示问题 - 优化数据获取和展示逻辑 - 完善分析器服务 - 新增 FastAPI 服务接口 - 改进账单清理器实现
This commit is contained in:
53
server/router/router.go
Normal file
53
server/router/router.go
Normal file
@@ -0,0 +1,53 @@
|
||||
// Package router 路由配置
|
||||
package router
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
"billai-server/handler"
|
||||
)
|
||||
|
||||
// Config 路由配置参数
|
||||
type Config struct {
|
||||
OutputDir string // 输出目录(用于静态文件服务)
|
||||
PythonPath string // Python 路径(用于健康检查显示)
|
||||
}
|
||||
|
||||
// Setup 设置所有路由
|
||||
func Setup(r *gin.Engine, cfg Config) {
|
||||
// 健康检查
|
||||
r.GET("/health", healthCheck(cfg.PythonPath))
|
||||
|
||||
// API 路由组
|
||||
setupAPIRoutes(r)
|
||||
|
||||
// 静态文件下载
|
||||
r.Static("/download", cfg.OutputDir)
|
||||
}
|
||||
|
||||
// healthCheck 健康检查处理器
|
||||
func healthCheck(pythonPath string) gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": "ok",
|
||||
"python_path": pythonPath,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// setupAPIRoutes 设置 API 路由
|
||||
func setupAPIRoutes(r *gin.Engine) {
|
||||
api := r.Group("/api")
|
||||
{
|
||||
// 账单上传
|
||||
api.POST("/upload", handler.Upload)
|
||||
|
||||
// 复核相关
|
||||
api.GET("/review", handler.Review)
|
||||
|
||||
// 账单查询
|
||||
api.GET("/bills", handler.ListBills)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user