1
0

Changed Update() handler accordingly to a new logic.

This commit is contained in:
Alexander Andreev 2022-10-21 04:38:53 +04:00
parent 6c08e4cb16
commit be5d0782b6
Signed by: Arav
GPG Key ID: 0388CC8FAA51063F

View File

@ -192,10 +192,10 @@ func (h *GuestbookHandlers) Update(w http.ResponseWriter, r *http.Request) {
} }
if strings.HasSuffix(r.URL.Path, "reply") { if strings.HasSuffix(r.URL.Path, "reply") {
rp := guestbook.Reply{ID: entryID} rp := guestbook.Reply{}
json.NewDecoder(r.Body).Decode(&rp) json.NewDecoder(r.Body).Decode(&rp)
isCreated, err := h.db.UpdateReply(&rp) isCreated, err := h.db.UpdateReply(entryID, &rp)
if err != nil { if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError) http.Error(w, err.Error(), http.StatusInternalServerError)
return return
@ -208,10 +208,10 @@ func (h *GuestbookHandlers) Update(w http.ResponseWriter, r *http.Request) {
w.Header().Add("Content-Type", "application/json") w.Header().Add("Content-Type", "application/json")
json.NewEncoder(w).Encode(&rp) json.NewEncoder(w).Encode(&rp)
} else { } else {
et := guestbook.Entry{ID: entryID} et := guestbook.Entry{}
json.NewDecoder(r.Body).Decode(&et) json.NewDecoder(r.Body).Decode(&et)
isCreated, err := h.db.UpdateEntry(&et) isCreated, err := h.db.UpdateEntry(entryID, &et)
if err != nil { if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError) http.Error(w, err.Error(), http.StatusInternalServerError)
return return