diff options
author | Julian T <julian@jtle.dk> | 2024-05-24 21:44:05 +0200 |
---|---|---|
committer | Julian T <julian@jtle.dk> | 2024-05-24 21:44:05 +0200 |
commit | eabd0e769c2bfef7a7aa748d794675d3ff7a920b (patch) | |
tree | 68308c5262d6c162b2d196866382abb651d0dff5 /tidsreg.go | |
parent | 2f83424ce8a0653e6e158318df1511daecf1a42d (diff) |
Add tasks
Diffstat (limited to 'tidsreg.go')
-rw-r--r-- | tidsreg.go | 19 |
1 files changed, 17 insertions, 2 deletions
@@ -198,13 +198,17 @@ func (s *Server) getEdit(w http.ResponseWriter, r *http.Request) { } id := int(idLarge) - task, err := s.srv.Db.QueryTask(&id) + entries, err := s.srv.Db.QueryEntry(&id) if err != nil { writeError(w, err.Error(), http.StatusInternalServerError) return } + if len(entries) < 1 { + writeError(w, "could not find entry by id", http.StatusNotFound) + return + } - page, err := s.srv.GetEntryPage(task) + page, err := s.srv.GetEntryPage(entries[0]) if err != nil { writeError(w, err.Error(), http.StatusInternalServerError) return @@ -223,6 +227,16 @@ func (s *Server) getEntries(w http.ResponseWriter, _ *http.Request) { s.renderTemplate(w, "entryRows.html", page) } +func (s *Server) getTasksList(w http.ResponseWriter, _ *http.Request) { + page, err := s.srv.GetTasksPage() + if err != nil { + writeError(w, err.Error(), http.StatusInternalServerError) + return + } + + s.renderTemplate(w, "tasksPage.html", page) +} + func main() { fmt.Println("Hello world!") @@ -239,6 +253,7 @@ func main() { r.HandleFunc("/save", s.putSave).Methods("PUT") r.HandleFunc("/entryRows", s.getEntries).Methods("GET") r.HandleFunc("/edit", s.getEdit).Methods("GET") + r.HandleFunc("/task/list", s.getTasksList).Methods("GET") r.HandleFunc("/", s.rootHandle) http.Handle("/", r) |