diff options
Diffstat (limited to 'internal/handlers/main.go')
-rw-r--r-- | internal/handlers/main.go | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/internal/handlers/main.go b/internal/handlers/main.go index dc8ba2b..efafcde 100644 --- a/internal/handlers/main.go +++ b/internal/handlers/main.go @@ -2,33 +2,37 @@ package handlers import ( "apjournal/config" + "apjournal/internal/database/repos" "apjournal/internal/models" "html/template" "log/slog" "net/http" "os" "strconv" + "time" + + "github.com/jmoiron/sqlx" ) // Handlers structure type Handlers struct { - cfg config.Config - // s *service.Service - log *slog.Logger + cfg config.Config + log *slog.Logger + repo *repos.Provider } // NewHandlers constructor func NewHandlers( // cfg config.Config, s *service.Service, l *slog.Logger, - cfg config.Config, l *slog.Logger, + cfg config.Config, l *slog.Logger, conn *sqlx.DB, ) *Handlers { if l == nil { l = slog.New(slog.NewJSONHandler(os.Stdout, nil)) } h := &Handlers{ - cfg: cfg, - // s: s, - log: l, + cfg: cfg, + log: l, + repo: repos.NewProvider(conn), } return h } @@ -49,7 +53,8 @@ func (h *Handlers) MainPage(w http.ResponseWriter, r *http.Request) { panic(err) } // tmpl.Execute(w, us) - us.ID = "test" + us.Username = "test" + us.BurnTime = time.Now().Add(time.Duration(24) * time.Hour) tmpl.ExecuteTemplate(w, "main", us) } @@ -88,16 +93,18 @@ func (h *Handlers) HandleForm(w http.ResponseWriter, r *http.Request) { Type: at, 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) + // TODO: redirect to the main page instead 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) + h.log.Info("got done request", "payload", r.PostForm) actionName := r.PostFormValue("name") h.log.Info("got postform request", "name", actionName) // change counter of user score |