1
0
Fork 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
1 changed files with 4 additions and 4 deletions

View File

@ -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