Пример #1
0
    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
Пример #2
0
    def insertFuel(self, json):
        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_dao = ResourceDAO()
            resource_id = resource_dao.insert(supplier_id, category_id,
                                              fuel_name, fuel_brand,
                                              fuel_quantity, fuel_price)
            fuel_dao = FuelDAO()
            fuel_id = fuel_dao.insert(resource_id, fuel_type, fuel_gallons)
            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), 201
        else:
            return jsonify(Error="Unexpected attributes in post request"), 400
Пример #3
0
 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
Пример #4
0
 def deleteFuel(self, fuid):
     dao = FuelDAO()
     if not dao.getFuelByID(fuid):
         return jsonify(Error="Fuel not found."), 404
     else:
         dao.delete(fuid)
         return jsonify(DeleteStatus="OK"), 200
Пример #5
0
 def insertFuel(self, form):
     print("form: ", form)
     if len(form) != 4:
         return jsonify(Error="Malformed post request")
     Fueltype = form['FuelType']
     Fueloctenage = form['FuelOctenage']
     Fueldescription = form['Fueldescription']
     resourceid = form['resourceid']
     if Fueltype and Fueloctenage and Fueldescription and resourceid:
         dao = FuelDAO()
         Fuelid = dao.insert(
             Fueltype,
             Fueloctenage,
             Fueldescription,
             resourceid,
         )
         result = self.build_fuel_attributes(
             Fuelid,
             Fueltype,
             Fueloctenage,
             Fueldescription,
             resourceid,
         )
         return jsonify(Fuel=result), 201
     else:
         return jsonify(Error="Unexpected attributes in post request")
Пример #6
0
 def getResourceIDByFuelID(self, Fuelid):
     dao = FuelDAO()
     row = dao.getResourceIDByFuelID(Fuelid)
     if not row:
         return jsonify(Error="Fuel Not Found "), 404
     else:
         Fuel = self.build_fuel_dict(row)
         return jsonify(Fuel=Fuel)
Пример #7
0
 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)
Пример #8
0
 def getAllResourceByKeyword(self, keyword):
     dao = FuelDAO()
     Resources_list = dao.getResourceByKeyWord(keyword)
     result_list = []
     for row in Resources_list:
         result = self.build_Fuel_dict(row)
         result_list.append(result)
     return jsonify(Resources=result_list)
Пример #9
0
 def getAllReservedFuels(self):
     dao = FuelDAO()
     fuel_list = dao.getAllReservedFuels()
     result_list = []
     for row in fuel_list:
         result = self.build_fuel_dict(row)
         result_list.append(result)
     return jsonify(Fuels=result_list)
Пример #10
0
 def getFuelByResourceId(self, resource_id):
     dao = FuelDAO()
     row = dao.getFuelByResourceId(resource_id)
     if not row:
         return jsonify(Error="Fuel Not Found"), 404
     else:
         fuel = self.build_fuel_dict(row)
         return jsonify(Fuel=fuel)
Пример #11
0
 def getFuelByLocation(self, location):
     dao = FuelDAO()
     fuel_list = dao.getFuelByLocation(location)
     result_list = []
     for row in fuel_list:
         result = self.build_Fuel_dict(row)
         result_list.append(result)
     return jsonify(Fuel=result_list)
Пример #12
0
 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
Пример #13
0
    def getAllFuel(self):
        dao = FuelDAO()
        Fuel_list = dao.getAllFuel()
        result_list = []
        for row in Fuel_list:
            result = self.build_fuel_dict(row)
            result_list.append(result)

        return jsonify(Fuel=Fuel_list)
Пример #14
0
 def insertFuelJson(self, json):
     ftype = json['ftype']
     fsupplier = json['fsupplier']
     fquantity = json['fquantity']
     flocation = json['flocation']
     if ftype and fsupplier and fquantity and flocation:
         dao = FuelDAO()
         result = dao.insert(ftype, fsupplier, fquantity, flocation)
         return jsonify(Fuel=result), 201
     else:
         return jsonify(Error="Unexpected attributes in post request"), 400
Пример #15
0
 def getFuelsBySupplierId(self, supplier_id):
     supplier_dao = SupplierDAO()
     if not supplier_dao.getSupplierById(supplier_id):
         return jsonify(Error="Supplier not found."), 404
     else:
         fuel_list = []
         result_list = []
         fuel_dao = FuelDAO()
         fuel_list = fuel_dao.getFuelsBySupplierId(supplier_id)
         for row in fuel_list:
             result = self.build_fuel_dict(row)
             result_list.append(result)
         return jsonify(Fuels=result_list)
Пример #16
0
 def searchFuel(self, args):
     supplierid = args.get("supplierid")
     dao = FuelDAO()
     Fuel_list = []
     if (len(args) == 1) and supplierid:
         Fuel_list = dao.getFuelBySupplier(supplierid)
     else:
         return jsonify(Error="Malformed query string"), 400
     result_list = []
     for row in Fuel_list:
         result = self.build_fuel_dict(row)
         result_list.append(result)
     return jsonify(Fuel=result_list)
Пример #17
0
 def insertFuelJson(self, json):
     Fueltype = json['FuelType']
     Fueloctenage = json['FuelOctenage']
     Fueldescription = json['FuelDescription']
     resourceid = json['ResourceID']
     if Fueltype and Fueloctenage and Fueldescription and resourceid:
         dao = FuelDAO()
         Fuelid = dao.insert(Fueltype, Fueloctenage, Fueldescription,
                             resourceid)
         result = self.build_fuel_attributes(Fuelid, Fueltype, Fueloctenage,
                                             Fueldescription, resourceid)
         return jsonify(Fuel=result), 201
     else:
         return jsonify(Error="Unexpected attributes in post request")
Пример #18
0
 def searchFuel(self, args):
     if len(args) > 1:
         return jsonify(Error="Malformed search string."), 400
     else:
         location = args.get("location")
         if location:
             dao = FuelDAO()
             fuel_list = dao.getFuelByLocation()
             # result_list = []
             # for row in fuel_list:
             #     result = self.build_fuel_dict(row)
             #     result_list.append(row)
             return jsonify(Fuel=fuel_list)
         else:
             return jsonify(Error="Malformed search string."), 400
Пример #19
0
 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)
Пример #20
0
 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()
Пример #21
0
 def insert(self, item, supplier_id):
     fuel_type = item['fuel_type']
     resource_name = item['resource_name']
     resource_price = item['resource_price']
     resource_city = item['resource_city']
     resource_quantity = item['resource_quantity']
     resource_description = item['resource_description']
     resource_date = item['resource_date']
     if fuel_type and resource_name and resource_price and resource_city and resource_quantity and resource_description and resource_date:
         dao = FuelDAO()
         rid = dao.insert(fuel_type, resource_name, resource_price,
                          resource_city, resource_quantity,
                          resource_description, resource_date, supplier_id)
         return jsonify(Fuel=self.build_fuel_attrs(
             fuel_type, resource_name, resource_price, resource_city,
             resource_quantity, resource_description, resource_date))
     else:
         return jsonify(Error="Unexpected attributes in POST request"), 400
Пример #22
0
 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
Пример #23
0
 def searchFuels(self, args):
     fuel_brand = args.get("fuel_brand")
     fuel_type = args.get("fuel_type")
     fuel_gallons = args.get("fuel_gallons")
     dao = FuelDAO()
     fuel_list = []
     if (len(args) == 1) and fuel_brand:
         fuel_list = dao.getFuelsByBrand(fuel_brand)
     elif (len(args) == 1) and fuel_type:
         fuel_list = dao.getFuelsByType(fuel_type)
     elif (len(args) == 1) and fuel_gallons:
         fuel_list = dao.getFuelsByGallons(fuel_gallons)
     elif (len(args) == 2) and fuel_type and fuel_gallons:
         fuel_list = dao.getFuelsByTypeAndGallons(fuel_type, fuel_gallons)
     else:
         return jsonify(Error="Malformed query string"), 400
     result_list = []
     for row in fuel_list:
         result = self.build_fuel_dict(row)
         result_list.append(result)
     return jsonify(Fuels=result_list)
Пример #24
0
 def getFuelByID(self, fuid):
     dao = FuelDAO()
     result = dao.getFuelByID()
     return jsonify(Fuel=result)
Пример #25
0
 def updateFuel(self, fuid, form):
     dao = FuelDAO()
     if not dao.getFuelByID(fuid):
         return jsonify(Error="Fuel not found."), 404
     else:
         return jsonify(dao.getFuelByID(fuid)), 201
Пример #26
0
 def getAllFuel(self):
     dao = FuelDAO()
     fuel_list = dao.getAllFuel()
     return jsonify(Fuel=fuel_list)