Beispiel #1
0
 def get(self, storeName):
     if itemModel.find_store_by_name(storeName):
         items = {}
         for item in itemModel.query.filter_by(storeName=storeName):
             items[item.item_id] = {"item_id": item.item_id, "itemName": item.itemName, "price": item.price}
         return jsonify({storeName: items})
     return {"Error": "Store Not Found"}, 404
Beispiel #2
0
 def delete(self, storeName, itemName):
     if itemModel.find_store_by_name(storeName):
         if itemModel.find_item_by_name(storeName, itemName):
             item = itemModel.find_item_by_name(storeName, itemName)
             item.delete_from_db()
             return {"Item": "Deleted Successfully"}
         return {"Error": "Item Not Found"}, 404
     return {"Error": "Store Not Found"}, 404
Beispiel #3
0
 def post(self, storeName, itemName):
     request_itemData = Item.parser.parse_args()
     if itemModel.find_store_by_name(storeName):
         if not itemModel.find_item_by_name(storeName, itemName):
             item = itemModel(storeName, itemName, request_itemData['price'])
             item.insert_or_update_from_db()
             return {"Item": "Item Added Successfully"}
         return {"Error": "Item Already Exist."}, 404
     return {"Error": "Store Not Found"}, 404
Beispiel #4
0
 def put(self, storeName, itemName):
     request_itemData = Item.parser.parse_args()
     if itemModel.find_store_by_name(storeName):
         item = itemModel.find_item_by_name(storeName, itemName)
         if item:
             item.price = request_itemData['price']
             item.insert_or_update_from_db()
             return {"Item found": "Updated"}
         item = itemModel(storeName, itemName, request_itemData['price'])
         item.insert_or_update_from_db()
         return {"Item not found": "Created"}
     return {"Error": "Store Not Found"}, 404
Beispiel #5
0
 def get(self, storeName, itemName):
     if itemModel.find_store_by_name(storeName):
         if itemModel.find_item_by_name(storeName, itemName):
             return itemModel.find_item_by_name(storeName, itemName).json()
         return {"Error": "Item Not Found"}, 404
     return {"Error": "No Store Found"}, 404