Пример #1
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()
Пример #2
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
Пример #3
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
Пример #4
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
Пример #5
0
    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()