diff --git a/internal/notes/views/views.go b/internal/notes/views/views.go index 6600412..adcc693 100644 --- a/internal/notes/views/views.go +++ b/internal/notes/views/views.go @@ -80,10 +80,17 @@ func delete(w http.ResponseWriter, r *http.Request) { } func save(w http.ResponseWriter, r *http.Request) { - title := r.PathValue("note") + oldTitle := r.PathValue("note") + title := r.FormValue("title") body := r.FormValue("body") + note := ¬es.Note{Title: title, Body: []byte(body)} note.Save() + + if oldTitle != title { + notes.DeleteNote(oldTitle) + } + http.Redirect(w, r, myurls.Reverse("view", urls.Repl{"note": title}), http.StatusFound) } diff --git a/templates/edit.tmpl.html b/templates/edit.tmpl.html index bc2b010..d6ea5b8 100644 --- a/templates/edit.tmpl.html +++ b/templates/edit.tmpl.html @@ -3,7 +3,10 @@ {{define "main"}}
- + +
Enter your note title
+
+