def delete(self, name): if Items.find_by_name(name): item = Items.find_by_name(name) item.delete_item() return '', 204 else: return f"item {name} doesn`t exist"
def add_item(id, req): try: res = db.session.query(Character).filter_by(id=id).one() w1 = Items(name=req['name'], desc=req['desc'], objs=res) w1.save_to_db() return jsonify({'msg': "success", 'data': res.to_json()}) except KeyError: return Errors("Missing Key Values", 400).to_json()
def post(self): parser = reqparse.RequestParser() parser.add_argument('items', type=dict, action='append', help="Name cannot be blank!") args = parser.parse_args() added = [] for i in range(len(args['items'])): if Items.find_by_name(args['items'][i]['name']): return "Item {} already exists".format(args['items'][i]['name']) else: trueargs = {'name':args['items'][i]['name'], 'price':args['items'][i]['price']} item = Items(**trueargs) item.add_item() added.append(trueargs) return added, 201
def admin_item(id): if request.method == 'DELETE': return delete(Items, id) # if request.method == 'PUT': # return upgrade_weapon(id) if request.method == 'GET': return Items.find_by_id(id) return jsonify({"ll": "ll}"})
def put(self, item_id: str) -> Response: """ PUT response method for updating a item. JSON Web Token is required. Authorization is required: Access(admin=true) :return: JSON object """ data = request.get_json() put_user = Items.objects(id=item_id).update(**data) return jsonify({'result': put_user})
def put(self, name): parser = reqparse.RequestParser() parser.add_argument('price', type=float, required=True, help="Price cannot be blank!") args = parser.parse_args() if Items.find_by_name(name): item = Items.find_by_name(name) item.price = args['price'] item.update_item() return item.json(), 201 argsfull = {'name': name, 'price': args['price']} item = Items(**argsfull) item.add_item() return item.json(), 201
def delete(self, user_id: str) -> Response: """ DELETE response method for deleting single item. JSON Web Token is required. Authorization is required: Access(admin=true) :return: JSON object """ authorized: bool = Items.objects.get( id=get_jwt_identity()).access.admin if authorized: output = Items.objects(id=user_id).delete() return jsonify({'result': output}) else: return forbidden()
def post(self, name): if Items.find_by_name(name): return f"item {name} already exists" parser = reqparse.RequestParser() parser.add_argument('price', type=float, required=True, help="Price cannot be blank!") args = parser.parse_args() argsfull = {'name':name, 'price': args['price']} item = Items(**argsfull) item.add_item() return item.json(), 201
def post(self) -> Response: """ POST response method for creating item. JSON Web Token is required. Authorization is required: Access(admin=true) :return: JSON object """ authorized: bool = Items.objects.get( id=get_jwt_identity()).access.admin if authorized: data = request.get_json() post_user = Items(**data).save() output = {'id': str(post_user.id)} return jsonify({'result': output}) else: return forbidden()
def admin_items(): if request.method == 'POST': return add(Items, request.get_json()) if request.method == 'GET': return Items.all_item() return jsonify({"msg": "ed"})
def get(self): # pylint: disable=no-member output = Items.objects() return jsonify({'result': output})
def get(self, name): if Items.find_by_name(name): item = Items.find_by_name(name) return item.json() else: return f"item {name} doesn`t exist"
def get(self): items = Items.get_all() itemtrue = [] for item in items: itemtrue.append(item.json()) return itemtrue