From d466cf8a4717e09cef6d8b3c39c06e0935dafba7 Mon Sep 17 00:00:00 2001 From: Adam Mathes Date: Wed, 18 Feb 2026 19:07:37 -0800 Subject: Fix mark-as-read regression and add debugging tools --- api/api.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'api/api.go') diff --git a/api/api.go b/api/api.go index 16e8dd6..8785cd4 100644 --- a/api/api.go +++ b/api/api.go @@ -108,18 +108,22 @@ func (s *Server) HandleItem(w http.ResponseWriter, r *http.Request) { switch r.Method { case http.MethodPut: - var i item.Item - if err := json.NewDecoder(r.Body).Decode(&i); err != nil { - jsonError(w, "invalid json", http.StatusBadRequest) + i := item.ItemById(id) + if i == nil { + jsonError(w, "item not found", http.StatusNotFound) return } - if i.Id == 0 { - i.Id = id + + if err := json.NewDecoder(r.Body).Decode(i); err != nil { + jsonError(w, "invalid json", http.StatusBadRequest) + return } + if i.Id != id { jsonError(w, "id mismatch", http.StatusBadRequest) return } + i.Save() jsonResponse(w, i) -- cgit v1.2.3