From be5d0782b6a93acd511b2da947b726071430f5be Mon Sep 17 00:00:00 2001 From: "Alexander \"Arav\" Andreev" Date: Fri, 21 Oct 2022 04:38:53 +0400 Subject: [PATCH] Changed Update() handler accordingly to a new logic. --- internal/handlers/handlers.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/internal/handlers/handlers.go b/internal/handlers/handlers.go index 13f35ff..5d97731 100644 --- a/internal/handlers/handlers.go +++ b/internal/handlers/handlers.go @@ -192,10 +192,10 @@ func (h *GuestbookHandlers) Update(w http.ResponseWriter, r *http.Request) { } if strings.HasSuffix(r.URL.Path, "reply") { - rp := guestbook.Reply{ID: entryID} + rp := guestbook.Reply{} json.NewDecoder(r.Body).Decode(&rp) - isCreated, err := h.db.UpdateReply(&rp) + isCreated, err := h.db.UpdateReply(entryID, &rp) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return @@ -208,10 +208,10 @@ func (h *GuestbookHandlers) Update(w http.ResponseWriter, r *http.Request) { w.Header().Add("Content-Type", "application/json") json.NewEncoder(w).Encode(&rp) } else { - et := guestbook.Entry{ID: entryID} + et := guestbook.Entry{} json.NewDecoder(r.Body).Decode(&et) - isCreated, err := h.db.UpdateEntry(&et) + isCreated, err := h.db.UpdateEntry(entryID, &et) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return