package handler import ( "net/http" "time" "financeiro-carvalho/internal/service" ) type DashboardHandler struct { svc *service.DashboardService gameSvc *service.GameService } func NewDashboardHandler(svc *service.DashboardService, gameSvc *service.GameService) *DashboardHandler { return &DashboardHandler{svc: svc, gameSvc: gameSvc} } func (h *DashboardHandler) Get(w http.ResponseWriter, r *http.Request) { month := r.URL.Query().Get("month") if month == "" { month = time.Now().Format("2006-01") } data, err := h.svc.Get(r.Context(), month) if err != nil { respondError(w, http.StatusInternalServerError, "failed to load dashboard") return } // Notify game engine about savings percentage for the current month only if month == time.Now().Format("2006-01") { h.gameSvc.NotifyAction(r.Context(), "savings_checked", map[string]any{ "pct": data.SavingsPct, "goal": data.SavingsGoalPct, }) } respondJSON(w, http.StatusOK, data) }