From b662265234d70d648a7adce74f3d9cc245456d3a Mon Sep 17 00:00:00 2001 From: GrailFinder Date: Thu, 4 Apr 2024 12:40:44 +0300 Subject: Feat: action-done endpoint --- internal/handlers/main.go | 11 +++++++++++ internal/server/router.go | 1 + 2 files changed, 12 insertions(+) diff --git a/internal/handlers/main.go b/internal/handlers/main.go index 38da212..dc8ba2b 100644 --- a/internal/handlers/main.go +++ b/internal/handlers/main.go @@ -94,3 +94,14 @@ func (h *Handlers) HandleForm(w http.ResponseWriter, r *http.Request) { // tmpl.Execute(w, us) tmpl.ExecuteTemplate(w, "main", us) } + +func (h *Handlers) HandleDoneAction(w http.ResponseWriter, r *http.Request) { + r.ParseForm() + h.log.Info("got postform request", "payload", r.PostForm) + actionName := r.PostFormValue("name") + h.log.Info("got postform request", "name", actionName) + // change counter of user score + // get action by name + tmpl := template.Must(template.ParseGlob("components/*.html")) + tmpl.ExecuteTemplate(w, "main", nil) +} diff --git a/internal/server/router.go b/internal/server/router.go index 726f8b8..75cf4f9 100644 --- a/internal/server/router.go +++ b/internal/server/router.go @@ -22,6 +22,7 @@ func (srv *server) ListenToRequests() { mux.HandleFunc("GET /ping", h.Ping) mux.HandleFunc("GET /", h.MainPage) mux.HandleFunc("POST /", h.HandleForm) + mux.HandleFunc("POST /done", h.HandleDoneAction) // ====== elements ====== mux.HandleFunc("GET /showform", h.ServeShowForm) -- cgit v1.2.3