def remove_favorite(cls, userId, modelKey, device_key=""): to_delete = Favorite.query(Favorite.model_key == modelKey, ancestor=ndb.Key(Account, userId)).fetch(keys_only=True) if len(to_delete) > 0: ndb.delete_multi(to_delete) # Send updates to user's other devices NotificationHelper.send_favorite_update(userId, device_key) return 200 else: # Favorite doesn't exist. Can't delete it return 404
def add_favorite(cls, fav, device_key=""): if Favorite.query(Favorite.model_key == fav.model_key, ancestor=ndb.Key(Account, fav.user_id)).count() == 0: # Favorite doesn't exist, add it fav.put() # Send updates to user's other devices NotificationHelper.send_favorite_update(fav.user_id, device_key) return 200 else: # Favorite already exists. Don't add it again return 304
def remove_favorite(cls, userId, modelKey, device_key=""): to_delete = Favorite.query(Favorite.model_key == modelKey, ancestor=ndb.Key(Account, userId)).fetch(keys_only=True) if len(to_delete) > 0: ndb.delete_multi(to_delete) if device_key: # Send updates to user's other devices NotificationHelper.send_favorite_update(userId, device_key) return 200 else: # Favorite doesn't exist. Can't delete it return 404
def add_favorite(cls, fav, device_key=""): if Favorite.query(Favorite.model_key == fav.model_key, ancestor=ndb.Key(Account, fav.user_id)).count() == 0: # Favorite doesn't exist, add it fav.put() if device_key: # Send updates to user's other devices NotificationHelper.send_favorite_update(fav.user_id, device_key) return 200 else: # Favorite already exists. Don't add it again return 304