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 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