Beispiel #1
0
 def post(self):
     database = database_access()
     collection = database['dashboard']
     data = Dashboard.parser.parse_args()
     query = {"product_name": data['product_name'], "price": data['price']}
     records = collection.insert(query)
     database.close()
     return {"message": "Row inserted successfully."}, 201
Beispiel #2
0
 def delete(self):
     data = CartDelete.parser.parse_args()
     database = database_access()
     collcart = database['cart']
     records = collcart.find(data)
     print(records)
     if records:
         for record in records:
             collcart.remove(record)
             return {'messege': "product is removed from cart"}
Beispiel #3
0
 def get(self):
     database = database_access()
     collection = database['cart']
     records = collection.find()
     services = []
     for record in records:
         services.append({
             'product_name': record['product_name'],
             'price': record['price']
         })
         return {'dashboard': services}
Beispiel #4
0
 def get(self):
     database = database_access()
     collection = database['dashboard']
     records = collection.find()
     services = []
     for record in records:
         if record['count'] is not 0:
             services.append({
                 'product_name': record['product_name'],
                 'price': record['price'],
                 'messege': 'stock is avaliable'
             })
             return {'dashboard': services}
         else:
             return {'messege': 'no product is avaliable !!'}
Beispiel #5
0
    def post(self):

        data = CartAdd.parser.parse_args()
        database = database_access()
        collection = database['dashboard']
        collcart = database['cart']
        records = collection.find(data)
        if records:
            for record in records:
                if record['count'] is not 0:
                    item = {
                        'product_name': record['product_name'],
                        'price': record['price'],
                        'count': record['count']
                    }
                    count = int(record['count']) - 1
                    collcart.insert(item)
                    collection.update_one(record, {"$set": {"count": count}})
                    return {'messege': 'product has been added to cart'}
                else:
                    return {'messege': "out of stock!!!"}