def deleteAccount(self, aid): dao = AccountDAO() if not dao.getAccountById(aid): return jsonify(Error="Account not found."), 404 else: dao.deleteAccount(aid) return jsonify(DeleteStatus="OK"), 200
def searchAccountCredentials(self, aid, args): daoAcc = AccountDAO() dao = CredentialDAO() if not daoAcc.getAccountById(aid): return jsonify(Error = 'Account Not Found'), 404 username = args.get('username') password = args.get('password') credentials_list = [] if (len(args) == 2) and username and password: credentials_list = dao.getAccountCredentialsByUsernamePassword(aid, username, password) elif (len(args) == 1) and username: credentials_list = dao.getAccountCredentialsByUsername(aid, username) elif (len(args) == 1) and password: credentials_list = dao.getAccountCredentialsByPassword(aid, password) else: return jsonify(Error = "Malformed query string"), 400 result_list = [] for row in credentials_list: result = self.build_credential_dict(row) result_list.append(row) return jsonify(Credentials = result_list)
def getAccountById(self, aid): dao = AccountDAO() row = dao.getAccountById(aid) if not row: return jsonify(Error="Account Not Found"), 404 else: account = self.build_account_dict(row) return jsonify(Account=account)
def getAllAccounts(self): dao = AccountDAO() accounts_list = dao.getAllAccounts() result_list = [] for account in accounts_list: result = self.build_account_dict(account) result_list.append(result) return jsonify(Accounts=result_list)
def getAccountCredentials(self, aid): daoAcc = AccountDAO() dao = CredentialDAO() if not daoAcc.getAccountById(aid): return jsonify(Error = 'Account Not Found'), 404 credentials_list = dao.getAccountCredentials(aid) results_list = [] for row in credentials_list: result = self.build_credential_dict(row) results_list.append(result) return jsonify(Credentials = 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)
def getAccountCity(self, aid): daoAcc = AccountDAO() dao = CityDAO() if not daoAcc.getAccountById(aid): return jsonify(Error='Account Not Found'), 404 cities_list = dao.getAccountCity(aid) result_list = [] for row in cities_list: result = self.build_city_dict(row) result_list.append(result) return jsonify(City=result_list)
def getAccountRegion(self, aid): daoAcc = AccountDAO() dao = RegionDAO() if not daoAcc.getAccountById(aid): return jsonify(Error='Account Not Found'), 404 regions_list = dao.getAccountRegion(aid) result_list = [] for row in regions_list: result = self.build_region_dict(row) result_list.append(result) return jsonify(Region=result_list)
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 getAccountWithThisUsername(self, username): daoCred = CredentialDAO() dao = AccountDAO() if not daoCred.getCredentialsByUsername(username): return jsonify(Error='Credentials Not Found'), 404 accounts_list = dao.getAccountWithThisUsername(username) result_list = [] for row in accounts_list: result = self.build_account_dict(row) result_list.append(result) return jsonify(Accounts=result_list)
def getAccountsOnThisRegion(self, rname): daoReg = RegionDAO() dao = AccountDAO() if not daoReg.getRegionByName(rname): return jsonify(Error="Region Not Found"), 404 accounts_list = dao.getAccountsOnThisRegion(rname) result_list = [] for row in accounts_list: result = self.build_account_dict(row) result_list.append(result) return jsonify(Accounts=result_list)
def getAccountsOnThisCity(self, cname): dao = AccountDAO() daoCities = CityDAO() if not daoCities.getCityByName(cname): return jsonify(Error="City Not Found"), 404 accounts_list = dao.getAccountsOnThisCity(cname) result_list = [] for row in accounts_list: result = self.build_account_dict(row) result_list.append(result) return jsonify(Accounts=result_list)
def addNewAccount(self, form): if len(form) != 4: return jsonify(Error="Malformed post request"), 400 else: afirst = form['afirst'] alast = form['alast'] email = form['email'] phone = form['phone'] if afirst and alast and email and phone: dao = AccountDAO() aid = dao.addNewAccount(afirst, alast, email, phone) result = self.build_account_attributes(aid, afirst, alast, email, phone) return jsonify(Account=result), 201 else: return jsonify( Error="Unexpected attributes in post request"), 400
def updateAccount(self, aid, form): dao = AccountDAO() if not dao.getAccountById(aid): return jsonify(Error="Account 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.updateAccount(aid, afirst, alast, email, phone) result = self.build_account_attributes(aid, afirst, alast, email, phone) return jsonify(Account=result), 200 else: return jsonify( Error="Unexpected attributes in update request"), 400
def searchAccountAddress(self, aid, args): daoAcc = AccountDAO() dao = AddressDAO() if not daoAcc.getAccountById(aid): return jsonify(Error='Account 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.getAccountAddressesByStreetNumberUnitZipCode( aid, street, number, unit, zipcode) elif (len(args) == 3) and street and number and unit: addresses_list = dao.getAccountAddressesByStreetNumberUnit( aid, street, number, unit) elif (len(args) == 3) and street and number and zipcode: addresses_list = dao.getAccountAddressesByStreetNumberZipCode( aid, street, number, zipcode) elif (len(args) == 3) and street and zipcode and unit: addresses_list = dao.getAccountAddressesByStreetZipCodeUnit( aid, street, zipcode, unit) elif (len(args) == 3) and number and unit and zipcode: addresses_list = dao.getAccountAddressesByNumberUnitZipCode( aid, number, unit, zipcode) elif (len(args) == 2) and street and number: addresses_list = dao.getAccountAddressesByStreetNumber( aid, street, number) elif (len(args) == 2) and street and unit: addresses_list = dao.getAccountAddressesByStreetUnit( aid, street, unit) elif (len(args) == 2) and street and zipcode: addresses_list = dao.getAccountAddressesByStreetZipCode( aid, street, zipcode) elif (len(args) == 2) and number and unit: addresses_list = dao.getAccountAddressesByNumberUnit( aid, number, unit) elif (len(args) == 2) and number and zipcode: addresses_list = dao.getAccountAddressesByNumberZipCode( aid, number, zipcode) elif (len(args) == 2) and unit and zipcode: addresses_list = dao.getAccountAddressesByUnitZipCode( aid, unit, zipcode) elif (len(args) == 1) and street: addresses_list = dao.getAccountAddressesByStreet(aid, street) elif (len(args) == 1) and number: addresses_list = dao.getAccountAddressesByNumber(aid, number) elif (len(args) == 1) and unit: addresses_list = dao.getAccountAddressesByUnit(aid, unit) elif (len(args) == 1) and zipcode: addresses_list = dao.getAccountAddressesByZipCode(aid, 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)
def searchAccounts(self, args): dao = AccountDAO() afirst = args.get('afirst') alast = args.get('alast') email = args.get('email') phone = args.get('phone') accounts_list = [] if (len(args) == 4) and afirst and alast and email and phone: accounts_list = dao.getAccountsByAFirstALastEmailPhone( afirst, alast, email, phone) elif (len(args) == 3) and afirst and alast and email: accounts_list = dao.getAccountsByAFirstALastEmail( afirst, alast, email) elif (len(args) == 3) and afirst and alast and phone: accounts_list = dao.getAccountsByAFirstALastPhone( afirst, alast, phone) elif (len(args) == 3) and afirst and phone and email: accounts_list = dao.getAccountsByAFirstPhoneEmail( afirst, phone, email) elif (len(args) == 3) and alast and email and phone: accounts_list = dao.getAccountsByALastEmailPhone( alast, email, phone) elif (len(args) == 2) and afirst and alast: accounts_list = dao.getAccountsByAFirstALast(afirst, alast) elif (len(args) == 2) and afirst and email: accounts_list = dao.getAccountsByAFirstEmail(afirst, email) elif (len(args) == 2) and afirst and phone: accounts_list = dao.getAccountsByAFirstPhone(afirst, phone) elif (len(args) == 2) and alast and email: accounts_list = dao.getAccountsByALastEmail(alast, email) elif (len(args) == 2) and alast and phone: accounts_list = dao.getAccountsByALastPhone(alast, phone) elif (len(args) == 2) and email and phone: accounts_list = dao.getAccountsByEmailPhone(email, phone) elif (len(args) == 1) and afirst: accounts_list = dao.getAccountsByAFirst(afirst) elif (len(args) == 1) and alast: accounts_list = dao.getAccountsByALast(alast) elif (len(args) == 1) and email: accounts_list = dao.getAccountsByEmail(email) elif (len(args) == 1) and phone: accounts_list = dao.getAccountsByPhone(phone) else: return jsonify(Error="Malformed query string"), 400 result_list = [] for row in accounts_list: result = self.build_account_dict(row) result_list.append(result) return jsonify(Accounts=result_list)
def searchAccountWithThisUsername(self, username, args): daoCred = CredentialDAO() dao = AccountDAO() if not daoCred.getCredentialsByUsername(username): return jsonify(Error='Credentials Not Found'), 404 afirst = args.get('afirst') alast = args.get('alast') email = args.get('email') phone = args.get('phone') accounts_list = [] if (len(args) == 4) and afirst and alast and email and phone: accounts_list = dao.getAccountsWithThisUsernameByAfirstAlastEmailPhone( username, afirst, alast, email, phone) elif (len(args) == 3) and afirst and alast and email: accounts_list = dao.getAccountsWithThisUsernameByAfirstAlastEmail( username, afirst, alast, email) elif (len(args) == 3) and afirst and alast and phone: accounts_list = dao.getAccountsWithThisUsernameByAfirstAlastPhone( username, afirst, alast, phone) elif (len(args) == 3) and afirst and phone and email: accounts_list = dao.getAccountsWithThisUsernameByAfirstPhoneEmail( username, afirst, phone, email) elif (len(args) == 3) and alast and email and phone: accounts_list = dao.getAccountsWithThisUsernameByAlastEmailPhone( username, alast, email, phone) elif (len(args) == 2) and afirst and alast: accounts_list = dao.getAccountsWithThisUsernameByAfirstAlast( username, afirst, alast) elif (len(args) == 2) and afirst and email: accounts_list = dao.getAccountsWithThisUsernameByAfirstEmail( username, afirst, email) elif (len(args) == 2) and afirst and phone: accounts_list = dao.getAccountsWithThisUsernameByAfirstPhone( username, afirst, phone) elif (len(args) == 2) and alast and email: accounts_list = dao.getAccountsWithThisUsernameByAlastEmail( username, alast, email) elif (len(args) == 2) and alast and phone: accounts_list = dao.getAccountsWithThisUsernameByAlastPhone( username, alast, phone) elif (len(args) == 2) and email and phone: accounts_list = dao.getAccountsWithThisUsernameByEmailPhone( username, email, phone) elif (len(args) == 1) and afirst: accounts_list = dao.getAccountsWithThisUsernameByAfirst( username, afirst) elif (len(args) == 1) and alast: accounts_list = dao.getAccountsWithThisUsernameByAlast( username, alast) elif (len(args) == 1) and email: accounts_list = dao.getAccountsWithThisUsernameByEmail( username, email) elif (len(args) == 1) and phone: accounts_list = dao.getAccountsWithThisUsernameByPhone( username, phone) else: return jsonify(Error="Malformed query string"), 400 result_list = [] for row in accounts_list: result = self.build_account_dict(row) result_list.append(result) return jsonify(Accounts=result_list)
def searchAccountsOnThisRegion(self, rname, args): daoReg = RegionDAO() dao = AccountDAO() if not daoReg.getRegionByName(rname): return jsonify(Error="Region Not Found"), 404 afirst = args.get('afirst') alast = args.get('alast') email = args.get('email') phone = args.get('phone') accounts_list = [] if (len(args) == 4) and afirst and alast and email and phone: accounts_list = dao.getAccountsOnThisRegionAfirstAlastEmailPhone( rname, afirst, alast, email, phone) elif (len(args) == 3) and afirst and alast and email: accounts_list = dao.getAccountsOnThisRegionByAfirstAlastEmail( rname, afirst, alast, email) elif (len(args) == 3) and afirst and alast and phone: accounts_list = dao.getAccountsOnThisRegionByAfirstAlastPhone( rname, afirst, alast, phone) elif (len(args) == 3) and afirst and phone and email: accounts_list = dao.getAccountsOnThisRegionByAfirstPhoneEmail( rname, afirst, phone, email) elif (len(args) == 3) and alast and email and phone: accounts_list = dao.getAccountsOnThisRegionByAlastEmailPhone( rname, alast, email, phone) elif (len(args) == 2) and afirst and alast: accounts_list = dao.getAccountsOnThisRegionByAfirstAlast( rname, afirst, alast) elif (len(args) == 2) and afirst and email: accounts_list = dao.getAccountsOnThisRegionByAfirstEmail( rname, afirst, email) elif (len(args) == 2) and afirst and phone: accounts_list = dao.getAccountsOnThisRegionByAfirstPhone( rname, afirst, phone) elif (len(args) == 2) and alast and email: accounts_list = dao.getAccountsOnThisRegionByAlastEmail( rname, alast, email) elif (len(args) == 2) and alast and phone: accounts_list = dao.getAccountsOnThisRegionByAlastPhone( rname, alast, phone) elif (len(args) == 2) and email and phone: accounts_list = dao.getAccountsOnThisRegionByEmailPhone( rname, email, phone) elif (len(args) == 1) and afirst: accounts_list = dao.getAccountsOnThisRegionByAfirst(rname, afirst) elif (len(args) == 1) and alast: accounts_list = dao.getAccountsOnThisRegionByAlast(rname, alast) elif (len(args) == 1) and email: accounts_list = dao.getAccountsOnThisRegionByEmail(rname, email) elif (len(args) == 1) and phone: accounts_list = dao.getAccountsOnThisRegionByPhone(rname, phone) else: return jsonify(Error="Malformed query string"), 400 result_list = [] for row in accounts_list: result = self.build_account_dict(row) result_list.append(result) return jsonify(Accounts=result_list)
def searchAccountsOnThisAddressID(self, addId, args): daoAdd = AddressDAO() dao = AccountDAO() if not daoAdd.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') accounts_list = [] if (len(args) == 4) and afirst and alast and email and phone: accounts_list = dao.getAccountsOnThisAddressIDByAfirstAlastEmailPhone( addId, afirst, alast, email, phone) elif (len(args) == 3) and afirst and alast and email: accounts_list = dao.getAccountsOnThisAddressIDByAfirstAlastEmail( addId, afirst, alast, email) elif (len(args) == 3) and afirst and alast and phone: accounts_list = dao.getAccountsOnThisAddressIDByAfirstAlastPhone( addId, afirst, alast, phone) elif (len(args) == 3) and afirst and phone and email: accounts_list = dao.getAccountsOnThisAddressIDByAfirstPhoneEmail( addId, afirst, phone, email) elif (len(args) == 3) and alast and email and phone: accounts_list = dao.getAccountsOnThisAddressIDByAlastEmailPhone( addId, alast, email, phone) elif (len(args) == 2) and afirst and alast: accounts_list = dao.getAccountsOnThisAddressIDByAfirstAlast( addId, afirst, alast) elif (len(args) == 2) and afirst and email: accounts_list = dao.getAccountsOnThisAddressIDByAfirstEmail( addId, afirst, email) elif (len(args) == 2) and afirst and phone: accounts_list = dao.getAccountsOnThisAddressIDByAfirstPhone( addId, afirst, phone) elif (len(args) == 2) and alast and email: accounts_list = dao.getAccountsOnThisAddressIDByAlastEmail( addId, alast, email) elif (len(args) == 2) and alast and phone: accounts_list = dao.getAccountsOnThisAddressIDByAlastPhone( addId, alast, phone) elif (len(args) == 2) and email and phone: accounts_list = dao.getAccountsOnThisAddressIDByEmailPhone( addId, email, phone) elif (len(args) == 1) and afirst: accounts_list = dao.getAccountsOnThisAddressIDByAfirst( addId, afirst) elif (len(args) == 1) and alast: accounts_list = dao.getAccountsOnThisAddressIDByAlast(addId, alast) elif (len(args) == 1) and email: accounts_list = dao.getAccountsOnThisAddressIDByEmail(addId, email) elif (len(args) == 1) and phone: accounts_list = dao.getAccountsOnThisAddressIDByPhone(addId, phone) else: return jsonify(Error="Malformed query string"), 400 result_list = [] for row in accounts_list: result = self.build_account_dict(row) result_list.append(result) return jsonify(Accounts=result_list)