diff --git a/internal/http/handlers.go b/internal/http/handlers.go index 1d1600f..02b89d5 100644 --- a/internal/http/handlers.go +++ b/internal/http/handlers.go @@ -201,10 +201,34 @@ func (h *Handlers) GuestbookAdminDeleteReply(w http.ResponseWriter, r *http.Requ } } -func (h *Handlers) GuestbookAdminUpdateReply(w http.ResponseWriter, r *http.Request) { -} +func (h *Handlers) GuestbookAdminReply(w http.ResponseWriter, r *http.Request) { -func (h *Handlers) GuestbookAdminNewReply(w http.ResponseWriter, r *http.Request) { + r.ParseForm() + + id, err := strconv.ParseInt(r.FormValue("entry_id"), 10, 64) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + + reply, err := guestbook.NewReply(id, r.FormValue("message")) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + + if r.URL.Query().Has("update") { + if err = h.guestbookDB.UpdateReply(reply); err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + } else { + err = h.guestbookDB.NewReply(reply) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + } } func (h *Handlers) RSS(w http.ResponseWriter, r *http.Request) {