def updateFuel(self, fuel_id, json): fuel_dao = FuelDAO() if not fuel_dao.getFuelById(fuel_id): return jsonify(Error="Fuel not found."), 404 else: supplier_id = json["supplier_id"] category_id = json["category_id"] fuel_name = json["fuel_name"] fuel_brand = json["fuel_brand"] fuel_quantity = json["fuel_quantity"] fuel_price = json["fuel_price"] fuel_type = json["fuel_type"] fuel_gallons = json["fuel_gallons"] if supplier_id and category_id and fuel_name and fuel_brand and ( fuel_quantity >= 0) and (fuel_price >= 0) and fuel_type and fuel_gallons: resource_id = fuel_dao.update(fuel_id, fuel_type, fuel_gallons) resource_dao = ResourceDAO() resource_dao.update(resource_id, supplier_id, category_id, fuel_name, fuel_brand, fuel_quantity, fuel_price) result = self.build_fuel_attributes(fuel_id, resource_id, supplier_id, category_id, fuel_name, fuel_brand, fuel_quantity, fuel_price, fuel_type, fuel_gallons) return jsonify(Fuel=result), 200 else: return jsonify( Error="Unexpected attributes in update request"), 400
def deleteFuel(self, Fuelid): dao = FuelDAO() if not dao.getFuelById(Fuelid): return jsonify(Error="Resource not found."), 404 else: dao.delete(Fuelid) return jsonify(DeleteStatus="OK"), 200
def getFuelById(self, fuel_id): dao = FuelDAO() row = dao.getFuelById(fuel_id) if not row: return jsonify(Error="Fuel Not Found"), 404 else: fuel = self.build_fuel_dict(row) return jsonify(Fuel=fuel)
def getFuelById(self, id): dao = FuelDAO() fuel_list = dao.getFuelById(id) result_list = [] for row in fuel_list: result = self.build_Fuel_dict(row) result_list.append(result) return jsonify(Fuel=result_list)
def deleteFuel(self, fuel_id): fuel_dao = FuelDAO() if not fuel_dao.getFuelById(fuel_id): return jsonify(Error="Fuel not found."), 404 else: resource_id = fuel_dao.delete(fuel_id) resource_dao = ResourceDAO() resource_dao.delete(resource_id) return jsonify(DeleteStatus="OK"), 200
def getFuelAddress(self, fuel_id): fuel_dao = FuelDAO() try: supplier_id = fuel_dao.getFuelById(fuel_id)[4] except Exception: return jsonify(Error="Fuel not found."), 404 supplier_dao = SupplierDAO() if not supplier_dao.getSupplierById(supplier_id): return jsonify(Error="Supplier not found."), 404 else: row = fuel_dao.getFuelAddress(supplier_id) if not row: return jsonify(Error="Address not found."), 404 else: fuel_address = self.build_address_dict(row) return jsonify(Address=fuel_address)
def updateResourceJson(self, Fuelid, json): dao = FuelDAO() if not dao.getFuelById(Fuelid): return jsonify(Error="Fuel not found."), 404 else: Fueltype = json['FuelType'] Fueloctenage = json['FuelOctenage'] Fueldescription = json['FuelDescription'] if Fueltype and Fueloctenage and Fueldescription: dao.update(Fuelid, Fueltype, Fueloctenage, Fueldescription) resourceid = dao.getResourceIDByFuelID(Fuelid) result = self.build_fuel_attributes(Fuelid, Fueltype, Fueloctenage, Fueldescription, resourceid) return jsonify(Fuel=result), 400 else: return jsonify( Error="Unexpected attributes in update request"), 400