postgres and such
All checks were successful
ci/woodpecker/push/build Pipeline was successful
ci/woodpecker/push/dryrun Pipeline was successful
ci/woodpecker/push/publish-tag Pipeline was successful
ci/woodpecker/push/publish-latest Pipeline was successful

This commit is contained in:
2024-06-17 23:37:43 -04:00
parent 088365c411
commit 6f7bcc9503
17 changed files with 423 additions and 36 deletions

View File

@@ -3,7 +3,7 @@ package handlers
import (
"net/http"
"github.com/google/uuid"
"github.com/gofrs/uuid/v5"
"michaelthomson.dev/mthomson/go-todos-app/services"
"michaelthomson.dev/mthomson/go-todos-app/templates/partials"
)
@@ -42,10 +42,74 @@ func (h *TodoHandler) Create(w http.ResponseWriter, r *http.Request) {
}
}
func (h *TodoHandler) Done(w http.ResponseWriter, r *http.Request) {
var err error
id, err := uuid.FromString(r.PathValue("id"))
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
todo, err := h.ts.GetTodoById(id)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
todo, err = h.ts.UpdateTodo(id, todo.Name, true)
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
err = partials.Todo(todo).Render(r.Context(), w)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
}
func (h *TodoHandler) Undone(w http.ResponseWriter, r *http.Request) {
var err error
id, err := uuid.FromString(r.PathValue("id"))
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
todo, err := h.ts.GetTodoById(id)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
todo, err = h.ts.UpdateTodo(id, todo.Name, false)
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
err = partials.Todo(todo).Render(r.Context(), w)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
}
func (h *TodoHandler) Delete(w http.ResponseWriter, r *http.Request) {
var err error
id, err := uuid.Parse(r.PathValue("id"))
id, err := uuid.FromString(r.PathValue("id"))
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)