コード例 #1
0
 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"
コード例 #2
0
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()
コード例 #3
0
 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
コード例 #4
0
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}"})
コード例 #5
0
ファイル: items.py プロジェクト: emp-daisy/ease-mart-api
 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})
コード例 #6
0
 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
コード例 #7
0
ファイル: items.py プロジェクト: emp-daisy/ease-mart-api
    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()
コード例 #8
0
 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
コード例 #9
0
ファイル: items.py プロジェクト: emp-daisy/ease-mart-api
    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()
コード例 #10
0
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"})
コード例 #11
0
ファイル: items.py プロジェクト: emp-daisy/ease-mart-api
 def get(self):
     # pylint: disable=no-member
     output = Items.objects()
     return jsonify({'result': output})
コード例 #12
0
 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"
コード例 #13
0
 def get(self):
     items = Items.get_all()
     itemtrue = []
     for item in items:
         itemtrue.append(item.json())
     return itemtrue