Ejemplo n.º 1
0
 def deleteRequester(self, rid):
     dao = RequesterDAO()
     if not dao.getRequesterById(rid):
         return jsonify(Error="Requester not found."), 404
     else:
         dao.deleteRequester(rid)
         return jsonify(DeleteStatus="OK"), 200
Ejemplo n.º 2
0
 def getRequesterById(self, rid):
     dao = RequesterDAO()
     row = dao.getRequesterById(rid)
     if not row:
         return jsonify(Error="Requester Not Found"), 404
     else:
         requester = self.build_requester_dict(row)
         return jsonify(Requester=requester)
    def getRequesterCity(self, rid):

        daoReq = RequesterDAO()
        dao = CityDAO()

        if not daoReq.getRequesterById(rid):
            return jsonify(Error='Requester Not Found'), 404

        cities_list = dao.getRequesterCity(rid)
        result_list = []
        for row in cities_list:
            result = self.build_city_dict(row)
            result_list.append(result)
        return jsonify(City=result_list)
Ejemplo n.º 4
0
    def getRequesterRegion(self, rid):

        daoReq = RequesterDAO()
        dao = RegionDAO()

        if not daoReq.getRequesterById(rid):
            return jsonify(Error='Requester Not Found'), 404

        regions_list = dao.getRequesterRegion(rid)
        result_list = []
        for row in regions_list:
            result = self.build_region_dict(row)
            result_list.append(result)
        return jsonify(Region=result_list)
    def getRequesterAddress(self, rid):

        daoReq = RequesterDAO()
        dao = AddressDAO()

        if not daoReq.getRequesterById(rid):
            return jsonify(Error='Requester Not Found'), 404

        address_list = dao.getRequesterAddress(rid)

        results_list = []
        for row in address_list:
            result = self.build_address_dict(row)
            results_list.append(result)
        return jsonify(Address=results_list)
Ejemplo n.º 6
0
    def updateRequester(self, rid, form):
        dao = RequesterDAO()
        if not dao.getRequesterById(rid):
            return jsonify(Error="Requester not found"), 404
        else:
            if len(form) != 4:
                return jsonify(Error="Malformed update request"), 400

            afirst = form['afirst']
            alast = form['alast']
            email = form['email']
            phone = form['phone']

            if afirst and alast and email and phone:
                dao.updateRequester(rid, afirst, alast, email, phone)
                result = self.build_requester_attributes(
                    rid, afirst, alast, email, phone)
                return jsonify(Requester=result), 200
            else:
                return jsonify(
                    Error="Unexpected attributes in update request"), 400
    def searchRequesterAddress(self, rid, args):

        daoReq = RequesterDAO()
        dao = AddressDAO()

        if not daoReq.getRequesterById(rid):
            return jsonify(Error='Requester Not Found'), 404

        street = args.get('street')
        number = args.get('number')
        unit = args.get('unit')
        zipcode = args.get('zipcode')

        addresses_list = []

        if (len(args) == 4) and street and number and unit and zipcode:
            addresses_list = dao.getRequesterAddressesByStreetNumberUnitZipCode(
                rid, street, number, unit, zipcode)
        elif (len(args) == 3) and street and number and unit:
            addresses_list = dao.getRequesterAddressesByStreetNumberUnit(
                rid, street, number, unit)
        elif (len(args) == 3) and street and number and zipcode:
            addresses_list = dao.getRequesterAddressesByStreetNumberZipCode(
                rid, street, number, zipcode)
        elif (len(args) == 3) and street and zipcode and unit:
            addresses_list = dao.getRequesterAddressesByStreetZipCodeUnit(
                rid, street, zipcode, unit)
        elif (len(args) == 3) and number and unit and zipcode:
            addresses_list = dao.getRequesterAddressesByNumberUnitZipCode(
                rid, number, unit, zipcode)
        elif (len(args) == 2) and street and number:
            addresses_list = dao.getRequesterAddressesByStreetNumber(
                rid, street, number)
        elif (len(args) == 2) and street and unit:
            addresses_list = dao.getRequesterAddressesByStreetUnit(
                rid, street, unit)
        elif (len(args) == 2) and street and zipcode:
            addresses_list = dao.getRequesterAddressesByStreetZipCode(
                rid, street, zipcode)
        elif (len(args) == 2) and number and unit:
            addresses_list = dao.getRequesterAddressesByNumberUnit(
                rid, number, unit)
        elif (len(args) == 2) and number and zipcode:
            addresses_list = dao.getRequesterAddressesByNumberZipCode(
                rid, number, zipcode)
        elif (len(args) == 2) and unit and zipcode:
            addresses_list = dao.getRequesterAddressesByUnitZipCode(
                rid, unit, zipcode)
        elif (len(args) == 1) and street:
            addresses_list = dao.getRequesterAddressesByStreet(rid, street)
        elif (len(args) == 1) and number:
            addresses_list = dao.getRequesterAddressesByNumber(rid, number)
        elif (len(args) == 1) and unit:
            addresses_list = dao.getRequesterAddressesByUnit(rid, unit)
        elif (len(args) == 1) and zipcode:
            addresses_list = dao.getRequesterAddressesByZipCode(rid, zipcode)
        else:
            return jsonify(Error="Malformed query string"), 400
        result_list = []
        for row in addresses_list:
            result = self.build_address_dict(row)
            result_list.append(result)
        return jsonify(Addresses=result_list)