diff --git a/models/shared.go b/models/shared.go index a7054d4..920e29d 100644 --- a/models/shared.go +++ b/models/shared.go @@ -12,9 +12,10 @@ import ( ) const ( - UserKey = "user" - ImprintKey = "imprint" - AuthCookieKey = "wakapi_auth" + UserKey = "user" + ImprintKey = "imprint" + AuthCookieKey = "wakapi_auth" + PersistentIntervalKey = "wakapi_summary_interval" ) type MigrationFunc func(db *gorm.DB) error diff --git a/routes/summary.go b/routes/summary.go index 268da1d..78ac89f 100644 --- a/routes/summary.go +++ b/routes/summary.go @@ -43,8 +43,14 @@ func (h *SummaryHandler) GetIndex(w http.ResponseWriter, r *http.Request) { rawQuery := r.URL.RawQuery q := r.URL.Query() if q.Get("interval") == "" && q.Get("from") == "" { - q.Set("interval", "today") + if intervalCookie, _ := r.Cookie(models.PersistentIntervalKey); intervalCookie != nil { + q.Set("interval", intervalCookie.Value) + } else { + q.Set("interval", "today") + } r.URL.RawQuery = q.Encode() + } else { + // TODO: Add a `Set-Cookie: interval` header to persit it on the front-end } summaryParams, _ := utils.ParseSummaryParams(r)