From eabd0e769c2bfef7a7aa748d794675d3ff7a920b Mon Sep 17 00:00:00 2001 From: Julian T Date: Fri, 24 May 2024 21:44:05 +0200 Subject: Add tasks --- tidsreg.go | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'tidsreg.go') diff --git a/tidsreg.go b/tidsreg.go index 28dea95..987a40f 100644 --- a/tidsreg.go +++ b/tidsreg.go @@ -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) -- cgit v1.2.3