diff --git a/db/db.go b/db/db.go index 9eacf9e..7d88799 100644 --- a/db/db.go +++ b/db/db.go @@ -197,6 +197,11 @@ func GetUpcomingTodos() ([]types.Todo, error) { return todos, nil } +func UpdateTodo(newValues types.Todo) error { + _, err := db.Exec("UPDATE items SET start=?, due=?, text=? WHERE id=?", toNullInt64(newValues.Start), toNullInt64(newValues.Due), newValues.Text, newValues.Id) + return err; +} + func SetCompleted(id int, completed bool) error { _, err := db.Exec("UPDATE items SET completed=? WHERE id=?", completed, id) return err diff --git a/main.go b/main.go index a91ec56..3bc259a 100644 --- a/main.go +++ b/main.go @@ -61,6 +61,7 @@ func addFrontendEndpoints(mux *http.ServeMux) { mux.HandleFunc("/upcoming", pages.UpcomingFragment) mux.HandleFunc("DELETE /delete/{id}", pages.DeleteItem) mux.HandleFunc("PATCH /set/{id}", pages.SetItemCompleted) + mux.HandleFunc("PUT /update", pages.UpdateItem) mux.HandleFunc("POST /new", pages.CreateItem) fileServer := http.FileServer(http.Dir("./static")) diff --git a/pages/templates/root.templ b/pages/templates/root.templ index 5cc2cd1..ed0c2b4 100644 --- a/pages/templates/root.templ +++ b/pages/templates/root.templ @@ -54,28 +54,50 @@ templ RootPage() {