示例#1
0
    def updateAddress(self, address_id, json):
        address_dao = AddressDAO()
        if not address_dao.getAddressById(address_id):
            return jsonify(Error="Address not found."), 404
        else:
            user_id = json["user_id"]
            addressline = json["addressline"]
            city = json["city"]
            state_province = json["state_province"]
            country = json["country"]
            zipcode = json["zipcode"]

            if user_id and addressline and city and state_province and country and zipcode:
                address_dao = AddressDAO()
                address_id = address_dao.update(address_id, user_id,
                                                addressline, city,
                                                state_province, country,
                                                zipcode)
                result = self.build_address_attributes(address_id, user_id,
                                                       addressline, city,
                                                       state_province, country,
                                                       zipcode)
                return jsonify(Address=result), 200
            else:
                return jsonify(
                    Error="Unexpected attributes in update request"), 400
示例#2
0
 def deleteAddressByID(self, add_id):
     dao = AddressDAO()
     if not dao.getAddressById(add_id):
         return jsonify(Error="Address not found."), 404
     else:
         dao.delete(add_id)
         return jsonify(DeleteStatus="OK"), 200
示例#3
0
 def getAddressByID(self, add_id):
     dao = AddressDAO()
     row = dao.getAddressById(add_id)
     if not row:
         return jsonify(Error="Address Not Found"), 404
     else:
         result = self.build_address_dict(row)
     return jsonify(Address=result)
 def getAddressById(self, address_id):
     dao = AddressDAO()
     row = dao.getAddressById(address_id)
     if not row:
         return jsonify(Error="User Not Found"), 404
     else:
         address = self.build_address_dict(row)
         return jsonify(Address=address)
 def getRegionByAddresId(self, address_id):
     dao = AddressDAO()
     if not dao.getAddressById(address_id):
         return jsonify(Error="Address Not Found"), 404
     regions_list = dao.getRegionByAddressId(address_id)
     result_list = []
     for row in regions_list:
         result = self.build_region_dict(row)
         result_list.append(result)
     return jsonify(Regions=result_list)
    def searchAdministratorsOnThisAddressID(self, addId, args):

        daoAd = AddressDAO()
        dao = AdministratorDAO()

        if not daoAd.getAddressById(addId):
            return jsonify(Error = 'Address Not Found'), 404

        afirst = args.get('afirst')
        alast = args.get('alast')
        email = args.get('email')
        phone = args.get('phone')

        administrators_list = []

        if(len(args) == 4) and afirst and alast and email and phone:
            administrators_list = dao.getAdministratorsOnThisAddressIDByAfirstAlastEmailPhone(addId, afirst, alast, email, phone)
        elif(len(args) == 3) and afirst and alast and email:
            administrators_list = dao.getAdministratorsOnThisAddressIDByAfirstAlastEmail(addId, afirst, alast, email)
        elif(len(args) == 3) and afirst and alast and phone:
            administrators_list = dao.getAdministratorsOnThisAddressIDByAfirstAlastPhone(addId, afirst, alast, phone)
        elif(len(args) == 3) and afirst and phone and email:
            administrators_list = dao.getAdministratorsOnThisAddressIDByAfirstPhoneEmail(addId, afirst, phone, email)
        elif(len(args) == 3) and alast and email and phone:
            administrators_list = dao.getAdministratorsOnThisAddressIDByAlastEmailPhone(addId, alast, email, phone)
        elif(len(args) == 2) and afirst and alast:
            administrators_list = dao.getAdministratorsOnThisAddressIDByAfirstAlast(addId, afirst, alast)
        elif(len(args) == 2) and afirst and email:
            administrators_list = dao.getAdministratorsOnThisAddressIDByAfirstEmail(addId, afirst, email)
        elif(len(args) == 2) and afirst and phone:
            administrators_list = dao.getAdministratorsOnThisAddressIDByAfirstPhone(addId, afirst, phone)
        elif(len(args) == 2) and alast and email:
            administrators_list = dao.getAdministratorsOnThisAddressIDByAlastEmail(addId, alast, email)
        elif(len(args) == 2) and alast and phone:
            administrators_list = dao.getAdministratorsOnThisAddressIDByAlastPhone(addId, alast, phone)
        elif(len(args) == 2) and email and phone:
            administrators_list = dao.getAdministratorsOnThisAddressIDByEmailPhone(addId, email, phone)
        elif(len(args) == 1) and afirst:
            administrators_list = dao.getAdministratorsOnThisAddressIDByAfirst(addId, afirst)
        elif(len(args) == 1) and alast:
            administrators_list = dao.getAdministratorsOnThisAddressIDByAlast(addId, alast)
        elif(len(args) == 1) and email:
            administrators_list = dao.getAdministratorsOnThisAddressIDByEmail(addId, email)
        elif(len(args) == 1) and phone:
            administrators_list = dao.getAdministratorsOnThisAddressIDByPhone(addId, phone)
        else:
            return jsonify(Error = "Malformed query string"), 400
        result_list = []
        for row in administrators_list:
            result = self.build_administrator_dict(row)
            result_list.append(result)
        return jsonify(Administrators = result_list)
    def getCityOfThisAddress(self, addId):

        daoAdd = AddressDAO()
        dao = CityDAO()

        if not daoAdd.getAddressById(addId):
            return jsonify(Error='Address Not Found'), 404

        cities_list = dao.getCityOfThisAddress(addId)
        result_list = []
        for row in cities_list:
            result = self.build_city_dict(row)
            result_list.append(result)
        return jsonify(City=result_list)
示例#8
0
    def getRegionOfThisAddress(self, addId):

        daoAdd = AddressDAO()
        dao = RegionDAO()

        if not daoAdd.getAddressById(addId):
            return jsonify(Error='Address Not Found'), 404

        regions_list = dao.getRegionOfThisAddress(addId)
        result_list = []
        for row in regions_list:
            result = self.build_region_dict(row)
            result_list.append(result)
        return jsonify(Region=result_list)
示例#9
0
    def getAccountsOnThisAddressID(self, addId):

        daoAdd = AddressDAO()
        dao = AccountDAO()

        if not daoAdd.getAddressById(addId):
            return jsonify(Error='Address Not Found'), 404

        accounts_list = dao.getAccountsWithThisAddressID(addId)
        result_list = []
        for row in accounts_list:
            result = self.build_account_dict(row)
            result_list.append(result)
        return jsonify(Accounts=result_list)
    def getAdministratorsOnThisAddressID(self, addId):

        daoAd = AddressDAO()
        dao = AdministratorDAO()

        if not daoAd.getAddressById(addId):
            return jsonify(Error = 'Address Not Found'), 404

        administrators_list = dao.getAdministratorsWithThisAddressID(addId)
        result_list = []

        for row in administrators_list:
            result = self.build_administrator_dict(row)
            result_list.append(result)
        return jsonify(Administrators = result_list)
示例#11
0
    def getRequestersOnThisAddressID(self, addId):

        dao = RequesterDAO()
        daoAdd = AddressDAO()

        if not daoAdd.getAddressById(addId):
            return jsonify(Error='Address Not Found'), 404

        requesters_list = dao.getRequestersWithThisAddressID(addId)
        result_list = []

        for row in requesters_list:
            result = self.build_requester_dict(row)
            result_list.append(result)
        return jsonify(Requesters=result_list)
    def updateAddress(self, addId, form):
        dao = AddressDAO()
        if not dao.getAddressById(addId):
            return jsonify(Error="Address not found"), 404
        else:
            if len(form) != 4:
                return jsonify(Error="Malformed update request"), 400

            street = form['street']
            number = form['number']
            unit = form['unit']
            zipcode = form['zipcode']

            if street and number and unit and zipcode:
                dao.updateAddress(addId, street, number, unit, zipcode)
                result = self.build_address_attributes(addId, street, number,
                                                       unit, zipcode)
                return jsonify(Address=result), 200
            else:
                return jsonify(
                    Error="Unexpected attributes in update request"), 400