def delete(self, name):
     item = ItemModel.find_item_by_name(name)
     if item:
         item.delete_from_db()
         return {'message': f"Item {name} deleted."}
     else:
         return {'message': f"Item {name} cannot be found in database."}
예제 #2
0
    def post(self, user_id):
        parser = reqparse.RequestParser()
        parser.add_argument('destination',
                            type=str,
                            required=True,
                            location='json')
        parser.add_argument('pickup', type=str, required=True, location='json')
        parser.add_argument('rider_id',
                            required=True,
                            type=int,
                            location='json')
        parser.add_argument('amountpaid',
                            required=True,
                            type=float,
                            location='json')
        parser.add_argument('ordereditems',
                            type=list,
                            required=True,
                            help="This field is required",
                            location='json')
        data = parser.parse_args()
        order = OrderModel(data['destination'], data['pickup'], user_id,
                           data['rider_id'], data['amountpaid'])

        order.save_to_db()
        for index in data['ordereditems']:
            item = ItemModel.find_by_name(index['name'])
            n_order = OrderItemModel(order.order_id, item.item_id,
                                     index['item_quantity'])
            n_order.save_to_db()
        return {"message": "Order was created successfully."}, 201
예제 #3
0
 def post(self, item_name):
     parser = reqparse.RequestParser()
     parser.add_argument('price',
                         type=float,
                         required=True,
                         location='json')
     parser.add_argument('category',
                         type=str,
                         required=True,
                         location='json')
     data = parser.parse_args()
     holder = CategoryModel.find_by_category_name(data['category'])
     if holder:
         item = ItemModel(item_name, data['price'], holder.category_id)
         item.save_to_db()
         return {"message": "item successfully added"}
     return {"message": "category not recogonzied"}
예제 #4
0
    def post(self):
        data = item_parser.parse_args()
        item = ItemModel(**data)

        db.session.add(item)
        db.session.commit()

        return {'item': item_schema.dump(item)}, 201
예제 #5
0
 def put(self, name):
     data = Item.parser.parse_args()
     item = ItemModel.find_by_name(name)
     if item is None:
         item = ItemModel(name, data['price'], data['store_id'])
     else:
         item.price = data['price']
     item.save_to_db()
     return item.json()
예제 #6
0
 def put(self, name):
     data = Item.parser.parse_args()
     item = ItemModel.find_by_name(name)
     if item:
         item.price = data['price']
     else:
         item = ItemModel(name, **data)
     item.insert()
     return item.json()
예제 #7
0
    def put(self, itemname):
        data = ItemResource.parser.parse_args()
        item = ItemModel.find_by_name(itemname)
        if item:
            item.price = data['price']
        else:
            item = ItemModel(itemname, **data)

        item.save_to_db()
        return item.json()
예제 #8
0
 def post(self, name):
     item = ItemModel.find_by_name(name)
     if item:
         return {'msg': f'An Item with name {name} already exist'}
     data = Item.parser.parse_args()
     item = ItemModel(name, data['price'], data['store_id'])
     try:
         item.save_to_db()
         return item.json()
     except:
         return {'msg': "An error occured"}
예제 #9
0
    def post(self, name):
        data = Item.parser.parse_args()
        item = ItemModel.find_by_name(name)
        if item:
            return {'msg': "item with name {} already exits".format(name)}, 400
        item = ItemModel(name, **data)
        try:
            item.insert()
        except:
            return {
                'msg': 'An error occured while inserting'
            }, 500  #internal server error

        return item.json(
        ), 201  #created              #202 okay  #404 Not Found #202 Accepted
예제 #10
0
    def post(self, itemname):
        item = ItemModel.find_by_name(itemname)
        if item:
            return {
                'message':
                "An item with name '{}' already exists.".format(name)
            }, 400

        data = ItemResource.parser.parse_args()  #
        item = ItemModel(itemname, **data)
        try:
            item.save_to_db()
        except:
            return {"message": "An error occurred inserting the item."}, 500

        return item.json(), 201
예제 #11
0
 def json(self):
     user = UserModel.find_by_id(self.user_id)
     rider = RiderModel.find_by_rider_id(self.rider_id)
     ridername = rider.rider_firstname + ' ' + rider.rider_lastname
     overitems = OrderItemModel.find_by_orderid(self.order_id)
     orderitems = []
     for order in overitems:
         item = ItemModel.find_by_id(order.item_id)
         orderitems.append(
             dict({
                 "item_name": item.item_name,
                 "item price": item.unit_price,
                 "quantity": order.item_quantity
             }))
     return {
         "username": user.username,
         "Ridername": ridername,
         "destination": self.destination,
         'pickup': self.pickup_point,
         'ordertime': str(self.ordertime),
         'amountpaid': self.amountpaid,
         "ordererditems": orderitems
     }
    def post(self, name):
        if ItemModel.find_item_by_name(name):
            return {
                'message': f"An item with name {name} already exists."
            }, 400

        data = Item.parser.parse_args()

        item = ItemModel(name, **data)

        try:
            item.save_to_db()
        except:
            return {
                'message': "An error occured while inserting an item."
            }, 500

        return item.json(), 201
예제 #13
0
 def delete(self, name):
     item = ItemModel.find_by_name(name)
     if item:
         item.delete()
     return {'message': 'Item Deleted'}, 204
예제 #14
0
 def get(self, item_name):
     item = ItemModel.find_by_name(item_name)
     if item:
         return item.json()
     return {'message': 'Item not found'}, 404
예제 #15
0
 def delete(self, name):
     item = ItemModel.find_by_name(name)
     if item:
         item.delete()
     return {'msg': 'item deleted'}
예제 #16
0
    def get(self, name):
        item = ItemModel.find_by_name(name)

        if item:
            return item.json(), 200
        return {'msg': "item not found"}, 404
 def get(self, name):
     item = ItemModel.find_item_by_name(name)
     if item:
         return item.json()
     return {'message': "Item not found"}, 404
예제 #18
0
 def get(self, name):
     item = ItemModel.find_by_name(name)
     if item:
         return item.json()
     return {'msg': 'Not found'}, 404
예제 #19
0
 def delete(self, itemname):
     item = ItemModel.find_by_name(itemname)
     if item:
         item.delete_from_db()
         return {'message': 'Item deleted.'}
     return {'message': 'Item not found.'}, 404