コード例 #1
0
    def searchFuel(self, args):
        if len(args) > 4:
            return jsonify(Error = "Malformed search string."), 400
        else:
            rid = args.get("rid")
            ftype = args.get("ftype")
            price = args.get("price")
            csize = args.get("csize")
            brand = args.get("brand")

            dao = FuelDAO()
            fuel_list = []
            if (len(args) == 1) and rid:
                fuel_list = dao.getFuelById(rid)
            elif (len(args) == 1) and ftype:
                fuel_list = dao.getFuelByType(ftype)
            elif (len(args) == 1) and price:
                fuel_list = dao.getFuelByPrice(price)
            elif (len(args) == 1) and csize:
                fuel_list = dao.getFuelByContainerSize(csize)
            elif (len(args) == 1) and brand:
                fuel_list = dao.getFuelByBrand(brand)
            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)
コード例 #2
0
    def getFuelByPrice(self, price):

        dao = FuelDAO()
        fuel_list = dao.getFuelByPrice(price)
        if not fuel_list:
            return jsonify(Error = "No Fuel found"), 404
        else:
            result_list = []
            for row in fuel_list:
                result = self.build_fuel_dict(row)
                result_list.append(result)
        return jsonify(Fuel = result_list)