Пример #1
0
 def update_account(client_id, account_id, change_account):
     account = AccountsDAO.get_account(client_id, account_id)
     if account:
         account.account_type = change_account.account_type
         update_count = AccountsDAO.update_account(account)
         return f"Updated {update_count} account", 201
     else:
         return "Account not found", 404
Пример #2
0
 def deposit_account(client_id, account_id, amount):
     try:
         account = AccountsDAO.get_account(client_id, account_id)
         if account:
             account.balance += amount
             AccountsDAO.update_account(account)
             return (f"{amount} has been deposited into {account.account_type}. "
                     f"Current Balance is {account.balance}", 200)
         else:
             return "Client or Account not found", 404
     except TypeError as e:
         return "There was an issue processing your request", 400
Пример #3
0
 def withdrawal_account(client_id, account_id, amount):
     account = AccountsDAO.get_account(client_id, account_id)
     if account:
         if account.balance - amount > 0:
             account.balance -= amount
             AccountsDAO.update_account(account)
             return (f"{amount} has been withdrawn from {account.account_type}. "
                     f"Current Balance is {account.balance}", 200)
         else:
             return f"Insufficient Funds", 422
     else:
         return "Client or Account not found", 404
Пример #4
0
 def get_client(id):
     sql = "Select id, name from clients where id = %s"
     cursor = connection.cursor()
     cursor.execute(sql, [id])
     record = cursor.fetchone()
     try:
         client = Client(id=record[0], name=record[1], accounts=AccountsDAO.get_accounts_by_client(record[0]))
         return client
     except TypeError as e:
         return False
Пример #5
0
    def get_all_clients():
        sql = "Select id, name from clients"
        cursor = connection.cursor()
        cursor.execute(sql)
        records = cursor.fetchall()
        clients = []

        for record in records:
            clients.append(Client(id=record[0], name=record[1], accounts=AccountsDAO.get_accounts_by_client(record[0])))

        return clients
Пример #6
0
 def transfer_account(client_id, account_id, transfer_account_id, amount):
     account = AccountsDAO.get_account(client_id, account_id)
     transfer_account = AccountsDAO.get_account(client_id, transfer_account_id)
     if account and transfer_account:
         if account.balance - amount > 0:
             account.balance -= amount
             transfer_account.balance += amount
             AccountsDAO.update_account(account)
             AccountsDAO.update_account(transfer_account)
             return f"Successfully Transferred funds", 200
         else:
             return "Insufficient funds", 422
     else:
         return "One or both of those accounts do not exist", 404
Пример #7
0
 def test_03_account_get_by_client(self):
     self.assertTrue(AccountsDAO.get_accounts_by_client(1))
Пример #8
0
 def create_account(account, client_id):
     return AccountsDAO.create_account(account, client_id)
Пример #9
0
 def delete_account(client_id, account_id):
     update_count = AccountsDAO.delete_account(client_id, account_id)
     return (f"Deleted {update_count} account", 204) if update_count else ("Account not found", 404)
Пример #10
0
 def test_04_account_get_one(self):
     self.assertTrue(AccountsDAO.get_account(1,
                                             AccountsDAOTests.account.id))
Пример #11
0
 def get_account_by_client_between(client_id, less_than, greater_than):
     accounts = []
     for account in AccountsDAO.get_accounts_by_client_between(client_id, less_than, greater_than):
         accounts.append(account.serialize())
     return accounts
Пример #12
0
 def get_accounts_by_client(id):
     accounts = []
     for account in AccountsDAO.get_accounts_by_client(id):
         accounts.append(account.serialize())
     return accounts
Пример #13
0
 def get_account(client_id, account_id):
     account = AccountsDAO.get_account(client_id, account_id)
     return account.serialize() if account else ("Account/Client not found", 404)
Пример #14
0
 def test_02_account_get_all(self):
     accounts = AccountsDAO.get_all_accounts()
     AccountsDAOTests.account = accounts.pop()
     self.assertTrue(accounts)
Пример #15
0
 def test_90_account_update(self):
     AccountsDAOTests.account.account_type = "Updated Test Account"
     self.assertTrue(AccountsDAO.update_account(AccountsDAOTests.account))
Пример #16
0
 def test_99_account_zdelete(self):
     self.assertTrue(
         AccountsDAO.delete_account(1, AccountsDAOTests.account.id))
Пример #17
0
 def test_account_get_between(self):
     self.assertTrue(AccountsDAO.get_accounts_by_client_between(1, 100, 0))
Пример #18
0
 def get_all_accounts():
     return AccountsDAO.get_all_accounts()
Пример #19
0
 def test_01_account_insert(self):
     self.assertTrue(AccountsDAO.create_account(AccountsDAOTests.account,
                                                1))