fix: analytics avg_daily_expense uses selected month/year instead of current
All checks were successful
CI / ci (push) Successful in 13s

This commit is contained in:
Cosmo
2026-03-01 05:31:05 +00:00
parent 9e06341564
commit 901173a337
3 changed files with 21 additions and 11 deletions

View File

@@ -253,11 +253,21 @@ func (h *FinanceHandler) Analytics(w http.ResponseWriter, r *http.Request) {
if !ok {
return
}
months, _ := strconv.Atoi(r.URL.Query().Get("months"))
q := r.URL.Query()
months, _ := strconv.Atoi(q.Get("months"))
if months <= 0 {
months = 6
}
analytics, err := h.svc.GetAnalytics(userID, months)
now := time.Now()
month, _ := strconv.Atoi(q.Get("month"))
year, _ := strconv.Atoi(q.Get("year"))
if month <= 0 {
month = int(now.Month())
}
if year <= 0 {
year = now.Year()
}
analytics, err := h.svc.GetAnalytics(userID, months, month, year)
if err != nil {
writeError(w, "failed to get analytics", http.StatusInternalServerError)
return