diff --git a/routes/summary.go b/routes/summary.go index 28e8942..6fffb66 100644 --- a/routes/summary.go +++ b/routes/summary.go @@ -45,13 +45,16 @@ 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") == "" { + // If the PersistentIntervalKey cookie is set, redirect to the correct summary page if intervalCookie, _ := r.Cookie(models.PersistentIntervalKey); intervalCookie != nil { - q.Set("interval", intervalCookie.Value) - } else { - q.Set("interval", "today") + redirectAddress := fmt.Sprintf("%s/summary?interval=%s", h.config.Server.BasePath, intervalCookie.Value) + http.Redirect(w, r, redirectAddress, http.StatusFound) } + + q.Set("interval", "today") r.URL.RawQuery = q.Encode() } else if q.Get("interval") != "" { + // Send a Set-Cookie header to persist the interval headerValue := fmt.Sprintf("%s=%s", models.PersistentIntervalKey, q.Get("interval")) w.Header().Add("Set-Cookie", headerValue) }