def post(self): data = Item.parser.parse_args() if ItemModel.find_item_by_name(data["name"]): return {"message": "Error: Item already exists"}, 409 item = ItemModel(**data) item.save() return item.json(), 201
def put(self, name): data = Item.parser.parse_args() try: item = ItemModel.find_item_by_name(name) if not item: item = ItemModel(**data) else: item.price = data["price"] item.save() return item.json() except: return {"message": "There was an error updating the item"}, 500
def create_item(category, data, user): new_item = ItemModel(**data, category_id=category.id, user_id=user.id) new_item.save() return jsonify(GetItemSchema().dump(new_item)), 201