aboutsummaryrefslogtreecommitdiffstats
path: root/api/api.go
diff options
context:
space:
mode:
Diffstat (limited to 'api/api.go')
-rw-r--r--api/api.go14
1 files changed, 9 insertions, 5 deletions
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)