def item_update(id): items = Item.query.filter_by(id=id) item_fields = item_schema.load(request.json) items.update(item_fields) db.session.commit() return jsonify(item_schema.dump(items[0]))
def item_create(): item_fields = item_schema.load(request.json) new_item = Item() new_item.name = item_fields["name"] db.session.add(new_item) db.session.commit() return jsonify(item_schema.dump(new_item))
def item_update(id): # update single item admin = User.query.get(get_jwt_identity()) if not admin.admin: return abort(401, description="Invalid user action.") items = Item.query.filter_by(id=id) item_fields = item_schema.load(request.json) items.update(item_fields) db.session.commit() return jsonify(item_schema.dump(items[0]))
def item_delete(id): # delete single item admin = User.query.get(get_jwt_identity()) if not admin.admin: return abort(401, description="Invalid user action.") item = Item.query.get(id) if not item: return "deleted" db.session.delete(item) db.session.commit() return jsonify(item_schema.dump(item))
def item_create(): # create new item item_fields = item_schema.load(request.json) admin = User.query.get(get_jwt_identity()) if not admin.admin: return abort(401, description="Invalid user action.") new_item = Item() new_item.name = item_fields["name"] new_item.description = item_fields["description"] new_item.price = round(item_fields["price"], 2) db.session.add(new_item) db.session.commit() return jsonify(item_schema.dump(new_item))
def item_delete(id): item = Item.query.get(id) db.session.delete(item) db.session.commit() return jsonify(item_schema.dump(item))
def item_show(id): item = Item.query.get(id) return jsonify(item_schema.dump(item))
def item_show(id): # return a single item item = Item.query.get(id) return jsonify(item_schema.dump(item))