chore: initial commit of HouseholdBudgetBook (backend, frontend, desktop)

This commit is contained in:
mapleferry committed 2026-11-29 21:29:06 +08:00
commit 4a5db3f1f9
167 files changed
+21732

No files matched your search

+46
View File
@@ -0,0 +1,46 @@
package api
import (
"net/http"
"strconv"
"household-book/service"
"github.com/gin-gonic/gin"
)
type DashboardHandler struct {
svc *service.DashboardService
}
func NewDashboardHandler(svc *service.DashboardService) *DashboardHandler {
return &DashboardHandler{svc: svc}
}
func (h *DashboardHandler) Summary(c *gin.Context) {
year := c.Query("year")
month := c.Query("month")
summary, err := h.svc.Summary(c.Request.Context(), year, month)
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": "获取摘要数据失败"})
return
}
c.JSON(http.StatusOK, summary)
}
func (h *DashboardHandler) Recent(c *gin.Context) {
limit := 5
if l := c.Query("limit"); l != "" {
if parsed, err := strconv.Atoi(l); err == nil && parsed > 0 && parsed <= 50 {
limit = parsed
}
}
items, err := h.svc.Recent(c.Request.Context(), limit)
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": "获取最近记录失败"})
return
}
c.JSON(http.StatusOK, items)
}