postgres and such
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user