// PutList saves the list for the given tag. func PutList(w http.ResponseWriter, r *http.Request) { // Get the context. c := appengine.NewContext(r) // Get the Key. vars := mux.Vars(r) key := vars["key"] datastore.RunInTransaction(c, func(c appengine.Context) error { // Get the original list. ol, ok := GetListHelper(c, w, r, key) if !ok { return fmt.Errorf("getting original list") } // Get the new list from the body. var nl List if !gorca.UnmarshalFromBodyOrFail(c, w, r, &nl) { return fmt.Errorf("unmarshalling") } // Merge the new list into the old list and remove deleted keys. delskeys := ol.Merge(&nl) if !gorca.DeleteStringKeys(c, w, r, delskeys) { return fmt.Errorf("deleting keys") } // Update the values. ol.LastModified = time.Now() ol.Name = nl.Name if !PutListHelper(c, w, r, ol) { return fmt.Errorf("putting list") } // Remove it from memcache memcache.Set(c, &memcache.Item{ Key: key, Value: []byte(fmt.Sprintf("%d", ol.LastModified.Unix())), }) // Return the updated list back. gorca.WriteJSON(c, w, r, ol) return nil }, nil) }
// DeleteRecipe deletes the recipe for the given tag. The currently // logged in user must own the recipe. Otherwise, an unauthorized error // is returned. func DeleteRecipe(w http.ResponseWriter, r *http.Request) { // Get the context. c := appengine.NewContext(r) // Get the Key. vars := mux.Vars(r) key := vars["key"] datastore.RunInTransaction(c, func(c appengine.Context) error { if !gorca.DeleteStringKeys(c, w, r, []string{key}) { return fmt.Errorf("deleting recipe") } gorca.WriteSuccessMessage(c, w, r) return nil }, nil) }