Exemple #1
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
    def insertAddress(self, json):
        user_id = json["user_id"]
        addressline = json["addressline"]
        city = json["city"]
        state_province = json["state_province"]
        country = json["country"]
        zipcode = json["zipcode"]

        user_dao = UserDAO()
        if not user_dao.getUserById(user_id):
            return jsonify(Error="User not found."), 404
        else:
            if user_id and addressline and city and state_province and country and zipcode:
                address_dao = AddressDAO()
                address_id = address_dao.insert(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), 201
            else:
                return jsonify(
                    Error="Unexpected attributes in post request"), 400
Exemple #3
0
    def insertAddress(self, form):
        if form and len(form) == 6:
            c_id = form['c_id']
            add_line1 = form['add_line1']
            add_line2 = form['add_line2']
            add_city = form['add_city']
            add_country = form['add_country']
            add_zip_code = form['add_zip_code']
            if c_id and add_line1 and add_line2 and add_city and add_country and add_zip_code:
                dao = AddressDAO()
                add_id = dao.insert(c_id, add_line1, add_line2, add_city,
                                    add_country, add_zip_code)
                result = {}
                result["add_id"] = add_id
                result["c_id"] = c_id
                result["add_line1"] = add_line1
                result["add_line2"] = add_line2
                result["add_city"] = add_city
                result["add_country"] = add_country
                result["add_zip_code"] = add_zip_code

                return jsonify(Address=result), 201
            else:
                return jsonify(Error="Malformed post request")
        else:
            return jsonify(Error="Malformed post request")
Exemple #4
0
 def getAddressByAID(self, id):
     if AccountDao().getAccountByID(id):
         dao = AddressDAO()
         addr = dao.getAddressByAID(id)
         return jsonify(Address = self._build_addr_dict(addr)), 201
     else:
         return jsonify(Error = "Account not Found."), 404
 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)
Exemple #6
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 getAllAddrees(self):
     dao = AddressDAO()
     address_list = dao.getAllAddress()
     result_list = []
     for row in address_list:
         result = self.build_address_dict(row)
         result_list.append(result)
     return jsonify(Address=result_list)
 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)
Exemple #9
0
 def getAllAddresses(self):
     dao = AddressDAO()
     address_list = dao.getAllAddresses()
     if not address_list:
         return jsonify(Error="Address Not Found"), 404
     else:
         result_list = []
         for row in address_list:
             result = self.build_address_dict(row)
             result_list.append(result)
     return jsonify(Addresses=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 getAddressesOnThisCity(self, cname):

        daoCities = CityDAO()
        dao = AddressDAO()

        if not daoCities.getCityByName(cname):
            return jsonify(Error="City Not Found"), 404

        addresses_list = dao.getAddressesOnThisCity(cname)
        result_list = []
        for row in addresses_list:
            result = self.build_address_dict(row)
            result_list.append(result)
        return jsonify(Addresses=result_list)
Exemple #12
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 getAdministratorAddress(self, adminId):

        daoAdmin = AdministratorDAO()
        dao = AddressDAO()

        if not daoAdmin.getAdministratorById(adminId):
            return jsonify(Error='Administrator Not Found'), 404

        address_list = dao.getAdministratorAddress(adminId)
        results_list = []
        for row in address_list:
            result = self.build_address_dict(row)
            results_list.append(result)
        return jsonify(Address=results_list)
    def getAccountAddress(self, aid):

        daoAcc = AccountDAO()
        dao = AddressDAO()

        if not daoAcc.getAccountById(aid):
            return jsonify(Error='Account Not Found'), 404

        address_list = dao.getAccountAddress(aid)
        results_list = []
        for row in address_list:
            result = self.build_address_dict(row)
            results_list.append(result)
        return jsonify(Address=results_list)
Exemple #15
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)
    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)
    def getAddressesOnThisRegion(self, rname):

        daoReg = RegionDAO()
        dao = AddressDAO()

        if not daoReg.getRegionByName(rname):
            return jsonify(Error="Region Not Found"), 404

        addresses_list = dao.getAddressesOnThisRegion(rname)
        result_list = []
        for row in addresses_list:
            result = self.build_address_dict(row)
            result_list.append(result)
        return jsonify(Addresses=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)
Exemple #19
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 getCreditCardAddress(self, cid):

        #  daoCred = CreditCardsDAO()
        dao = AddressDAO()

        # if not daoCred.getCreditCardById(cid):
        #     return jsonify(Error="Credit Card Not Found"), 404

        addresses_list = dao.getCreditCardAddress(cid)

        result_list = []
        for row in addresses_list:
            result = self.build_address_dict(row)
            result_list.append(result)
        return jsonify(Addresses=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)
 def getAddressesByUserId(self, user_id):
     user_dao = UserDAO()
     if not user_dao.getUserById(user_id):
         return jsonify(Error="User not found."), 404
     else:
         address_list = []
         result_list = []
         dao = AddressDAO()
         address_list = dao.getAddressesByUserId(user_id)
         # if not address_list:
         #     return jsonify(Error = "Address Not Found"), 404
         # else:
         for row in address_list:
             result = self.build_address_dict(row)
             result_list.append(result)
         return jsonify(Addresses=result_list)
    def getSupplierAddress(self, sid):

        daoSup = SupplierDAO()
        dao = AddressDAO()

        if not daoSup.getSupplierById(sid):
            return jsonify(Error='Supplier Not Found'), 404

        address_list = dao.getSupplierAddress(sid)

        results_list = []

        for row in address_list:
            result = self.build_address_dict(row)
            results_list.append(result)
        return jsonify(Address=results_list)
    def searchAddresses(self, args):
        city = args.get("city")
        state_province = args.get("state_province")
        country = args.get("country")
        zipcode = args.get("zipcode")

        dao = AddressDAO()
        address_list = []
        if (len(args) == 1) and city:
            address_list = dao.getAddressesByCity(city)
        elif (len(args) == 1) and state_province:
            address_list = dao.getAddressesByStateOrProvince(state_province)
        elif (len(args) == 1) and country:
            address_list = dao.getAddressesByCountry(country)
        elif (len(args) == 1) and zipcode:
            address_list = dao.getAddressesByZipcode(zipcode)
        elif (len(args) == 2) and city and country:
            address_list = dao.getAddressesByCityAndCountry(city, country)
        else:
            return jsonify(Error="Malformed query string"), 400
        result_list = []
        for row in address_list:
            result = self.build_address_dict(row)
            result_list.append(result)
        return jsonify(Addresses=result_list)
Exemple #25
0
 def updateAddress(self,aid, form):
     if AccountDao().getAccountByID(aid):
         if form and len(form)>=5:
              country = form.get('ADCountry')
              state = form.get('ADState')
              city = form.get('RCity')
              neighborhood = form.get('ADNeighborhood')
              street = form.get('ADStreet')
              number = form.get('ADNumber')
              zip = form.get('ADZipCode')
              if country and state and city and street and zip:
                  dao = AddressDAO()
                  addr = dao.update(aid, country, state, city, neighborhood,street,number,zip)
                  result = self._build_addr_dict(addr)
                  return jsonify(Address = result), 201
              else:
                  return jsonify(Error="Unexpected attributes in post request"), 400
         return jsonify(Error = "Malformed post request"), 400
     else:
         return jsonify(Error = "Account not Found."), 404
Exemple #26
0
 def searchAddresses(self, args):
     city = args.get('city')
     country = args.get('country')
     dao = AddressDAO()
     if (len(args) == 2) and city and country:
         address_list = dao.getAddressesByCityAndCountry(city, country)
     elif (len(args) == 1) and city:
         address_list = dao.getAddressesByCity(city)
     elif (len(args) == 1) and country:
         address_list = dao.getAddressesByCountry(country)
     else:
         return jsonify(Error="Malformed query string"), 400
     if not address_list:
         return jsonify(Error="Address Not Found"), 404
     else:
         result_list = []
         for row in address_list:
             result = self.build_address_dict(row)
             result_list.append(result)
     return jsonify(Address=result_list)
    def addNewAddress(self, form):
        if len(form) != 6:
            return jsonify(Error="Malformed post request"), 400
        else:
            street = form['street']
            number = form['number']
            unit = form['unit']
            zipcode = form['zipcode']
            aid = form['aid']
            cname = form['cname']

            if street and number and unit and zipcode and aid and cname:
                dao = AddressDAO()
                addId = dao.addNewAddress(street, number, unit, zipcode, aid,
                                          cname)
                result = self.build_address_attributes(addId, street, number,
                                                       unit, zipcode)
                return jsonify(Address=result), 201
            else:
                return jsonify(
                    Error="Unexpected attributes in post request"), 400
    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
    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
    def searchCreditCardAddress(self, cid, args):

        #  daoCred = CreditCardsDAO()
        dao = AddressDAO()

        #    if not daoCred.getCreditCardById(cid):
        #        return jsonify(Error="Credit Card 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.getAddressOnThisCreditCardByStreetNumberUnitZipCode(
                cid, street, number, unit, zipcode)
        elif (len(args) == 3) and street and number and unit:
            addresses_list = dao.getAddressesOnThisCreditCardByStreetNumberUnit(
                cid, street, number, unit)
        elif (len(args) == 3) and street and number and zipcode:
            addresses_list = dao.getAddressesOnThisCreditCardByStreetNumberZipCode(
                cid, street, number, zipcode)
        elif (len(args) == 3) and street and zipcode and unit:
            addresses_list = dao.getAddressesOnThisCreditCardByStreetZipCodeUnit(
                cid, street, zipcode, unit)
        elif (len(args) == 3) and number and unit and zipcode:
            addresses_list = dao.getAddressesOnThisCreditCardByNumberUnitZipCode(
                cid, number, unit, zipcode)
        elif (len(args) == 2) and street and number:
            addresses_list = dao.getAddressesOnThisCreditCardByStreetNumber(
                cid, street, number)
        elif (len(args) == 2) and street and unit:
            addresses_list = dao.getAddressesOnThisCreditCardByStreetUnit(
                cid, street, unit)
        elif (len(args) == 2) and street and zipcode:
            addresses_list = dao.getAddressesOnThisCreditCardByStreetZipCode(
                cid, street, zipcode)
        elif (len(args) == 2) and number and unit:
            addresses_list = dao.getAddressesOnThisCreditCardByNumberUnit(
                cid, number, unit)
        elif (len(args) == 2) and number and zipcode:
            addresses_list = dao.getAddressesOnThisCreditCardByNumberZipCode(
                cid, number, zipcode)
        elif (len(args) == 2) and unit and zipcode:
            addresses_list = dao.getAddressesOnThisCreditCardByUnitZipCode(
                cid, unit, zipcode)
        elif (len(args) == 1) and street:
            addresses_list = dao.getAddressesOnThisCreditCardByStreet(
                cid, street)
        elif (len(args) == 1) and number:
            addresses_list = dao.getAddressesOnThisCreditCardByNumber(
                cid, number)
        elif (len(args) == 1) and unit:
            addresses_list = dao.getAddressesOnThisCreditCardByUnit(cid, unit)
        elif (len(args) == 1) and zipcode:
            addresses_list = dao.getAddressesOnThisCreditCardByZipCode(
                cid, 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)