diff options
Diffstat (limited to 'internal/handlers')
-rw-r--r-- | internal/handlers/main.go | 40 |
1 files changed, 27 insertions, 13 deletions
diff --git a/internal/handlers/main.go b/internal/handlers/main.go index efafcde..1f2276c 100644 --- a/internal/handlers/main.go +++ b/internal/handlers/main.go @@ -38,7 +38,10 @@ func NewHandlers( } // FIXME: global userscore for test -var us models.UserScore +var us = models.UserScore{ + Username: "test", + BurnTime: time.Now().Add(time.Duration(24) * time.Hour), +} func (h *Handlers) Ping(w http.ResponseWriter, r *http.Request) { h.log.Info("got ping request") @@ -53,8 +56,8 @@ func (h *Handlers) MainPage(w http.ResponseWriter, r *http.Request) { panic(err) } // tmpl.Execute(w, us) - us.Username = "test" - us.BurnTime = time.Now().Add(time.Duration(24) * time.Hour) + // us.Username = "test" + // us.BurnTime = time.Now().Add(time.Duration(24) * time.Hour) tmpl.ExecuteTemplate(w, "main", us) } @@ -73,19 +76,20 @@ func (h *Handlers) HandleForm(w http.ResponseWriter, r *http.Request) { magnitude = uint8(1) } } + repeat := false var at models.ActionType switch r.PostFormValue("act_type") { case "plus": at = models.ActionTypePlus case "minus": at = models.ActionTypeMinus + repeat = true default: h.log.Warn("uknown actiontype", "type", r.PostFormValue("act_type")) } - repeat := false - if r.PostFormValue("repeatable") == "on" { - repeat = true - } + // if r.PostFormValue("repeatable") == "on" { + // repeat = true + // } // convert map to action object act := models.Action{ Name: r.PostFormValue("name"), @@ -94,12 +98,14 @@ func (h *Handlers) HandleForm(w http.ResponseWriter, r *http.Request) { Repeatable: repeat, } // TODO: check that name + userid key is unique - us.Actions = append(us.Actions, act) - tmpl := template.Must(template.ParseGlob("components/*.html")) - // tmpl := template.Must(template.ParseFiles("components/index.html")) - // tmpl.Execute(w, us) + us.Actions = append(us.Actions, &act) // TODO: redirect to the main page instead - tmpl.ExecuteTemplate(w, "main", us) + http.Redirect(w, r, "/", 302) + + // tmpl := template.Must(template.ParseGlob("components/*.html")) + // // tmpl := template.Must(template.ParseFiles("components/index.html")) + // // tmpl.Execute(w, us) + // tmpl.ExecuteTemplate(w, "main", us) } func (h *Handlers) HandleDoneAction(w http.ResponseWriter, r *http.Request) { @@ -109,6 +115,14 @@ func (h *Handlers) HandleDoneAction(w http.ResponseWriter, r *http.Request) { h.log.Info("got postform request", "name", actionName) // change counter of user score // get action by name + for _, act := range us.Actions { + if act.Name != actionName { + continue + } + us.UpdateScore(act) + h.log.Info("show action", "act", act, "us", us) + } tmpl := template.Must(template.ParseGlob("components/*.html")) - tmpl.ExecuteTemplate(w, "main", nil) + tmpl.ExecuteTemplate(w, "main", us) + // http.Redirect(w, r, "/", 302) } |