Changed Update() handler accordingly to a new logic.
This commit is contained in:
parent
6c08e4cb16
commit
be5d0782b6
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user