def updateWater(self, water_id, json): water_dao = WaterDAO() if not water_dao.getWaterById(water_id): return jsonify(Error="Water not found."), 404 else: supplier_id = json["supplier_id"] category_id = json["category_id"] water_name = json["water_name"] water_brand = json["water_brand"] water_quantity = json["water_quantity"] water_price = json["water_price"] water_size = json["water_size"] water_container = json["water_container"] water_type = json["water_type"] water_exp_date = json["water_exp_date"] if supplier_id and category_id and water_name and water_brand and water_quantity and ( water_price >= 0 ) and water_size and water_container and water_type and water_exp_date: resource_id = water_dao.update(water_id, water_size, water_container, water_type, water_exp_date) resource_dao = ResourceDAO() resource_dao.update(resource_id, supplier_id, category_id, water_name, water_brand, water_quantity, water_price) result = self.build_water_attributes( water_id, resource_id, supplier_id, category_id, water_name, water_brand, water_quantity, water_price, water_size, water_container, water_type, water_exp_date) return jsonify(Water=result), 200 else: return jsonify( Error="Unexpected attributes in update request"), 400
def insertWater(self, json): supplier_id = json["supplier_id"] category_id = json["category_id"] water_name = json["water_name"] water_brand = json["water_brand"] water_quantity = json["water_quantity"] water_price = json["water_price"] water_size = json["water_size"] water_container = json["water_container"] water_type = json["water_type"] water_exp_date = json["water_exp_date"] if supplier_id and category_id and water_name and water_brand and water_quantity and ( water_price >= 0 ) and water_size and water_container and water_type and water_exp_date: resource_dao = ResourceDAO() resource_id = resource_dao.insert(supplier_id, category_id, water_name, water_brand, water_quantity, water_price) water_dao = WaterDAO() water_id = water_dao.insert(resource_id, water_size, water_container, water_type, water_exp_date) result = self.build_water_attributes(water_id, resource_id, supplier_id, category_id, water_name, water_brand, water_quantity, water_price, water_size, water_container, water_type, water_exp_date) return jsonify(Water=result), 201 else: return jsonify(Error="Unexpected attributes in post request"), 400
def deleteWater(self, waterid): dao = WaterDAO() if not dao.getWaterById(waterid): return jsonify(Error="Resource not found"), 404 else: dao.delete(waterid) return jsonify(DeleteStatus="OK"), 200
def getWaterByID(self, waterid): dao = WaterDAO() row = dao.getWaterById(waterid) if not row: return jsonify(Error="Water Not Found "), 404 else: water = self.build_water_dict(row) return jsonify(Water=water)
def getWaterByResourceID(self, resourceid): dao = WaterDAO() row = dao.getWaterByResourceID(resourceid) if not row: return jsonify(Error="Water Not Found "), 404 else: Water = self.build_waterdetails_dict(row) return jsonify(Water=Water)
def getResourceIDByWaterID(self, Waterid): dao = WaterDAO() row = dao.getResourceIDByWaterID(Waterid) if not row: return jsonify(Error="Water Not Found "), 404 else: Water = self.build_water_dict(row) return jsonify(Water=Water)
def getAllWater(self): dao = WaterDAO() water_list = dao.getAllWater() result_list = [] for row in water_list: result = self.build_water_dict(row) result_list.append(result) return jsonify(Water=result_list)
def deleteWater(self, water_id): water_dao = WaterDAO() if not water_dao.getWaterById(water_id): return jsonify(Error="Water not found."), 404 else: resource_id = water_dao.delete(water_id) resource_dao = ResourceDAO() resource_dao.delete(resource_id) return jsonify(DeleteStatus="OK"), 200
def insertWaterJson(self, json): watersize = json['WaterSize'] waterdescription = json['WaterDescription'] resourceid = json['ResourceID'] if resourceid and watersize and waterdescription: dao = WaterDAO() waterid = dao.insert(watersize, waterdescription, resourceid) result = self.build_water_attributes(waterid, watersize, waterdescription, resourceid) return jsonify(water=result), 201 else: return jsonify(Error="Unexpected attributes in post request")
def getWatersBySupplierId(self, supplier_id): supplier_dao = SupplierDAO() if not supplier_dao.getSupplierById(supplier_id): return jsonify(Error="Supplier not found."), 404 else: water_list = [] result_list = [] water_dao = WaterDAO() water_list = water_dao.getWatersBySupplierId(supplier_id) for row in water_list: result = self.build_water_dict(row) result_list.append(result) return jsonify(Waters=result_list)
def insertWater(self, form): print("form: ", form) if len(form) != 3: return jsonify(Error="Malformed post request") resourceid = form['resourceid'] watersize = form['watersize'] waterdescription = form['waterdescription'] if resourceid and watersize and waterdescription: dao = WaterDAO() waterid = dao.insert(resourceid, watersize, waterdescription) result = self.build_water_attributes(waterid, resourceid, watersize, waterdescription) return jsonify(Water=result) else: return jsonify(Error="Unexpected attributes in post request")
def getDAO(self, type): if (type == 'babyfood'): return babyFoodDAO() elif (type == 'dryfood'): return dryFoodDAO() elif (type == 'cannedfood'): return cannedFoodDAO() elif (type == 'medication'): return MedicationDAO() elif (type == 'batteries'): return BatteryDAO() elif (type == 'clothing'): return ClothingDAO() elif (type == 'heavyequipment'): return HeavyEquipmentDAO() elif (type == 'ice'): return IceDAO() elif (type == 'powertools'): return PowerToolsDAO() elif (type == 'fuel'): return FuelDAO() elif (type == 'medicaldevices'): return MedicalDevicesDAO() elif (type == 'powergenerator'): return PowerGeneratorDAO() elif (type == 'hygiene'): return HygieneDAO() elif (type == 'water'): return WaterDAO()
def getWaterAddress(self, water_id): water_dao = WaterDAO() try: supplier_id = water_dao.getWaterById(water_id)[6] except Exception: return jsonify(Error="Water not found."), 404 supplier_dao = SupplierDAO() if not supplier_dao.getSupplierById(supplier_id): return jsonify(Error="Supplier not found."), 404 else: row = water_dao.getWaterAddress(supplier_id) if not row: return jsonify(Error="Address Not Found"), 404 else: address = self.build_address_dict(row) return jsonify(Address=address)
def searchWater(self, args): watersize = args.get("watersize") supplierid = args.get("supplierid") dao = WaterDAO() water_list = [] if (len(args) == 2) and watersize and supplierid: water_list = dao.getWaterBySupplierAndSize(supplierid, watersize) elif (len(args) == 1) and supplierid: water_list = dao.getWaterBySupplier(supplierid) elif (len(args) == 1) and watersize: water_list = dao.getWaterBySize(watersize) else: return jsonify(Error="Malformed query string"), 404 result_list = [] for row in water_list: result = self.build_water_dict(row) result_list.append(row) return jsonify(Water=result_list)
def searchWaters(self, args): water_brand = args.get("water_brand") water_container = args.get("water_container") water_type = args.get("water_type") dao = WaterDAO() water_list = [] if (len(args) == 1) and water_brand: water_list = dao.getWatersByBrand(water_brand) elif (len(args) == 1) and water_container: water_list = dao.getWatersByContainer(water_container) elif (len(args) == 1) and water_type: water_list = dao.getWatersByType(water_type) else: return jsonify(Error="Malformed query string"), 400 result_list = [] for row in water_list: result = self.build_water_dict(row) result_list.append(result) return jsonify(Waters=result_list)
def updateResourceJson(self, waterid, json): dao = WaterDAO() if not dao.getWaterById(waterid): return jsonify(Error="Resource not found"), 404 else: watersize = json['watersize'] waterdescription = json['waterdescription'] if watersize and waterdescription: dao.update(waterid, watersize, waterdescription) resourceid = dao.getResourceIDByWaterID(waterid) result = self.build_water_attributes(waterid, resourceid, watersize, waterdescription) return jsonify(Water=result), 200 else: return jsonify( Error="Unexpected attributes in post request"), 400
def updateResource(self, waterid, form): dao = WaterDAO() if not dao.getWaterById(waterid): return jsonify(Error="Resource not found"), 404 else: if (len(form) != 2): return jsonify(Error="Malformed update request") else: watersize = form['watersize'] waterdescription = form['waterdescription'] if watersize and waterdescription: dao.update(waterid, watersize, waterdescription) resourceid = dao.getResourceIDByWaterID(waterid) result = self.build_water_attributes( waterid, resourceid, watersize, waterdescription) return jsonify(Water=result), 400 else: return jsonify( Error="Unexpected attributes in update request"), 404