From ebe1836ac6dc0099d6e809fbcd3d4a6a07f7c5fc Mon Sep 17 00:00:00 2001 From: Daste Date: Sat, 19 Nov 2022 09:52:44 +0100 Subject: [PATCH] Write a Set-Cookie header with the last used summary interval --- routes/summary.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/routes/summary.go b/routes/summary.go index 78ac89f..28e8942 100644 --- a/routes/summary.go +++ b/routes/summary.go @@ -4,10 +4,12 @@ import ( "github.com/gorilla/mux" conf "github.com/muety/wakapi/config" "github.com/muety/wakapi/middlewares" + "github.com/muety/wakapi/models" "github.com/muety/wakapi/models/view" su "github.com/muety/wakapi/routes/utils" "github.com/muety/wakapi/services" "github.com/muety/wakapi/utils" + "fmt" "net/http" ) @@ -49,8 +51,9 @@ func (h *SummaryHandler) GetIndex(w http.ResponseWriter, r *http.Request) { q.Set("interval", "today") } r.URL.RawQuery = q.Encode() - } else { - // TODO: Add a `Set-Cookie: interval` header to persit it on the front-end + } else if q.Get("interval") != "" { + headerValue := fmt.Sprintf("%s=%s", models.PersistentIntervalKey, q.Get("interval")) + w.Header().Add("Set-Cookie", headerValue) } summaryParams, _ := utils.ParseSummaryParams(r)