From 87fc89a816ac4230b2652d963dde4aeb9e74926d Mon Sep 17 00:00:00 2001 From: John O'Keefe Date: Sat, 17 Oct 2026 16:54:21 -0400 Subject: [PATCH] refactor(router): one WeekStatsData mapper for the dashboard page and week-widget fragment --- internal/router/frontend.go | 40 ++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/internal/router/frontend.go b/internal/router/frontend.go index 397a8668..52d55f76 100644 --- a/internal/router/frontend.go +++ b/internal/router/frontend.go @@ -468,16 +468,8 @@ func registerFrontendRoutes(cfg *Config) { weekSvc, weekErr := cfg.StatisticsService.ThisWeek(c.Request().Context(), pgtype.UUID{Bytes: userUUID, Valid: true}, user.Timezone, weekScope) if weekErr == nil { - week = &templates.WeekStatsData{ - WeekMinutes: weekSvc.WeekMinutes, - WeekPages: weekSvc.WeekPages, - WeekSessions: weekSvc.WeekSessions, - WeekBooks: weekSvc.WeekBooks, - PrevMinutes: weekSvc.PrevMinutes, - ActiveToday: weekSvc.ActiveToday, - CurrentStreak: weekSvc.CurrentStreak, - LibraryID: libRes.LibraryID, - } + wk := weekStatsData(weekSvc, libRes.LibraryID) + week = &wk } else { log.Printf("ThisWeek widget failed: %v", weekErr) } @@ -816,16 +808,8 @@ func registerFrontendRoutes(cfg *Config) { } } } - err = templates.DashboardWeekWidget(templates.WeekStatsData{ - WeekMinutes: weekSvc.WeekMinutes, - WeekPages: weekSvc.WeekPages, - WeekSessions: weekSvc.WeekSessions, - WeekBooks: weekSvc.WeekBooks, - PrevMinutes: weekSvc.PrevMinutes, - ActiveToday: weekSvc.ActiveToday, - CurrentStreak: weekSvc.CurrentStreak, - LibraryID: libRes.LibraryID, - }, widgetLibType).Render(c.Request().Context(), &buf) + err = templates.DashboardWeekWidget(weekStatsData(weekSvc, libRes.LibraryID), + widgetLibType).Render(c.Request().Context(), &buf) if err != nil { return err } @@ -1680,3 +1664,19 @@ func (cfg *Config) GetHealth(c *echo.Context) error { }, }) } + +// weekStatsData maps the statistics weekly aggregate to the widget's +// template shape (shared by the dashboard page and the HTMX +// week-widget fragment). +func weekStatsData(weekSvc services.WeekSummaryStats, libraryID string) templates.WeekStatsData { + return templates.WeekStatsData{ + WeekMinutes: weekSvc.WeekMinutes, + WeekPages: weekSvc.WeekPages, + WeekSessions: weekSvc.WeekSessions, + WeekBooks: weekSvc.WeekBooks, + PrevMinutes: weekSvc.PrevMinutes, + ActiveToday: weekSvc.ActiveToday, + CurrentStreak: weekSvc.CurrentStreak, + LibraryID: libraryID, + } +}