This commit is contained in:
lbenedar
2026-03-05 15:08:06 +03:00
parent 8df6f1c6e9
commit b8fad1a63f

View File

@@ -76,14 +76,24 @@ func (app *application) snippetCreate(w http.ResponseWriter, r *http.Request) {
} }
func (app *application) snippetCreatePost(w http.ResponseWriter, r *http.Request) { func (app *application) snippetCreatePost(w http.ResponseWriter, r *http.Request) {
title := "0 snail" err := r.ParseForm()
content := "0 snail\nClimb Mount Fuji,\nBut slowly, slowly!\n\n-Kobayshi Issa" if err != nil {
expires := 7 app.clientError(w, http.StatusBadRequest)
return
}
title := r.PostForm.Get("title")
content := r.PostForm.Get("content")
expires, err := strconv.Atoi(r.PostForm.Get("expires"))
if err != nil {
app.clientError(w, http.StatusBadRequest)
return
}
id, err := app.snippets.Insert(title, content, expires) id, err := app.snippets.Insert(title, content, expires)
if err != nil { if err != nil {
app.serverError(w, err) app.serverError(w, err)
return return
} }
http.Redirect(w, r, fmt.Sprintf("/snippet/view/%d", id), http.StatusSeeOther) http.Redirect(w, r, fmt.Sprintf("/snippet/view/%d", id), http.StatusSeeOther)
} }