class AccountService:
    account_dao = AccountDAOImpl()

    @classmethod
    def create_account(cls, account, client_id):
        return cls.account_dao.create_account(account, client_id)

    @classmethod
    def all_accounts(cls, client_id):
        return cls.account_dao.all_accounts(client_id)

    @classmethod
    def get_account(cls, client_id, account_id):
        return cls.account_dao.get_account(client_id, account_id)

    @classmethod
    def get_bounds(cls, client_id, low_bound, high_bound):
        accounts = cls.all_accounts(client_id)

        refined_search = []

        for acc in accounts:
            print(acc["saved"])
            if low_bound <= int(acc["saved"]) <= high_bound:
                refined_search.append(acc)

        return refined_search

    @classmethod
    def update_account(cls, change):
        return cls.account_dao.update_account(change)

    @classmethod
    def delete_account(cls, client_id, account_id):
        return cls.account_dao.delete_account(client_id, account_id)

    @classmethod
    def add_funds(cls, client_id, account_id, amount):
        account = cls.account_dao.get_account(client_id, account_id)
        account.saved += amount
        cls.update_account(account)
        return jsonify(account.json())

    @classmethod
    def remove_funds(cls, client_id, account_id, amount):
        account = cls.account_dao.get_account(client_id, account_id)
        if account.saved >= amount:
            account.saved -= amount
            cls.update_account(account)
            return jsonify(account.json())
        else:
            raise InsufficientFunds("Insufficient Funds")

    @classmethod
    def transfer_funds(cls, client_id, account_id, dest_id, amount):
        try:
            cls.remove_funds(client_id, account_id, amount)
            return cls.add_funds(client_id, dest_id, amount)
        except InsufficientFunds as f:
            raise f
class AccountService:
    account_dao = AccountDAOImpl()

    @classmethod
    def create_account(cls, account):
        return cls.account_dao.create_account(account)

    @classmethod
    def all_accounts(cls):
        return cls.account_dao.all_accounts()

    @classmethod
    def get_account_by_id(cls, account_id):
        if account_id:
            return cls.account_dao.get_account(account_id)
        else:
            raise ResourceUnavailable(f"There is no account by id: {account_id} - Not Found")

    @classmethod
    def update_account(cls, account):
        return cls.account_dao.update_account(account)

    @classmethod
    def delete_account(cls, account_id):
        return cls.account_dao.delete_account(account_id)
Beispiel #3
0
 def get_all_accounts_for_client(cls, client_id):
     accounts = [
         account.json()
         for account in AccountDAOImpl.get_all_accounts_for_client(
             int(client_id))
     ]
     return accounts
Beispiel #4
0
 def get_all_accounts_in_range(cls, client_id, range1, range2):
     accounts = [
         account.json()
         for account in AccountDAOImpl.get_all_accounts_in_range(
             int(client_id), int(range1), int(range2))
     ]
     return accounts
Beispiel #5
0
 def update_account_with_id(cls, client_id, account_id, amount):
     ret = AccountDAOImpl.update_account_with_id(int(client_id),
                                                 int(account_id),
                                                 int(amount))
     if not ret:
         return "Not a valid account"
     return ret
Beispiel #6
0
class AccountServices:
    account_dao = AccountDAOImpl()

    @classmethod
    def create_account(cls, account):
        return cls.account_dao.create_account(account)

    @classmethod
    def all_accounts(cls, client_id):
        return cls.account_dao.all_accounts(client_id)

    @classmethod
    def get_account_by_id(cls, account_id, client_id):
        return cls.account_dao.get_account(account_id, client_id)

    @classmethod
    def update_account(cls, account, client_id):
        return cls.account_dao.update_account(account, client_id)

    @classmethod
    def delete_account(cls, account_id, client_id):
        return cls.account_dao.delete_account(account_id, client_id)

    @classmethod
    def get_account_balance_range(cls, balance, client_id):
        accounts = cls.all_accounts(client_id)

        refined_search = []

        for account in accounts:
            if account["balance"] <= balance <= account["balance"]:
                refined_search.append(account)

        return refined_search

    @classmethod
    def deposit(cls, account_id, client_id):
        try:
            account = cls.account_dao.get_account(account_id, client_id)
            amount = float
            account.balance += amount
            cls.update_account(account, client_id)
            return account.balance
        except UserNotFound:
            return "No such account or client exists", 404
        except InsufficientFunds:
            return "Insufficient Funds", 422

    @classmethod
    def withdraw(cls, account_id, client_id):
        try:
            account = cls.account_dao.get_account(account_id, client_id)
            amount = float
            account.balance += amount
            cls.update_account(account, client_id)
            return account.balance
        except UserNotFound:
            return "No such account or client exists", 404
        except InsufficientFunds:
            return "Insufficient Funds", 422
Beispiel #7
0
 def get_account_with_id(cls, client_id, account_id):
     ret = [
         account.json() for account in AccountDAOImpl.get_account_with_id(
             int(client_id), int(account_id))
     ]
     if not ret:
         return "Not a valid account"
     return ret
class AccountService:
    account_serv = AccountDAOImpl()

    @classmethod
    def create_account(cls, account):
        return cls.account_serv.create_account(account)

    @classmethod
    def all_account(cls):
        return cls.account_serv.all_account()

    @classmethod
    def get_account_id(cls, account_id):
        return cls.account_serv.get_account_id(account_id)

    # ---- update account with an ID
    @classmethod
    def update_account(cls, account_id):
        return cls.account_serv.update_account(account_id)

    # ----------------Delete account by id

    @classmethod
    def delete_account(cls, account_id):
        return cls.account_serv.delete_account(account_id)
#  user can deposit money
    @classmethod
    def deposit_amount(cls, account_id, client_id):
        try:
            acct = cls.account_dao.get_account(account_id, client_id)
            amount: float
            acct.account_balance += amount
            cls.update_account(acct, client_id)
            return acct.account_balance
        except ResourceUnavailable as e:
            return "Opps,tThe client or account does not exists", 404
        except ResourceNotFound as r:
            return "There is not enough money"
# -- user can withdraw money
    @classmethod
    def withdraw_amount(cls, account_id, client_id):
        try:
            acct = cls.account_dao.get_account(account_id, client_id)
            amount: float
            acct.account_balance -= amount
            cls.update_account(acct, client_id)
            return acct.account_balance
        except ResourceUnavailable as e:
            return "The client or account exists", 404
        except ResourceNotFound as r:
            return "There is not enough found", 422
class AccountService:

    account_dao = AccountDAOImpl()

    @classmethod
    def create_account(cls, account):
        return cls.account_dao.create_account(account)

    @classmethod
    def all_account(cls, client_id):
        return cls.account_dao.all_account(client_id)

    @classmethod
    def get_account(cls, account_id):
        return cls.account_dao.get_account(account_id)

    @classmethod
    def get_account_by_id(cls, cl_id, account_id):
        return cls.account_dao.get_account_by_id(cl_id, account_id)

    @classmethod
    def update_account(cls, account):
        # add some logic
        return cls.account_dao.update_account(account)

    @classmethod
    def delete_account(cls, account_id):
        return cls.account_dao.delete_account(account_id)

    @classmethod
    def deposit(cls, deposit_amt):
        return cls.account_dao.update_account(deposit_amt)

    # @classmethod
    # def withdraw(cls, account_id):
    #     if 0 < cls.account_balance < cls.account_balance:
    #         account["account_balance"] -= account.account_balance    #
    #     return cls.account_dao.update_account(account_id)

    @classmethod
    def transfer_fund(cls, transfer_amt):
        cls.deposit(transfer_amt)

    @classmethod
    def get_specific_account(cls, account_balance):
        accounts = cls.all_account()
        refined_search = []
        for acc in accounts:
            if acc["account_balance"] <= account_balance:
                refined_search.append(acc)
        return refined_search
Beispiel #10
0
class AccountService:
    # account_dao = AccountDAOTemp()
    account_dao = AccountDAOImpl()

    @classmethod
    def create_account(cls, account):
        return cls.account_dao.create_account(account), 201

    @classmethod
    def all_accounts(cls):
        return cls.account_dao.all_accounts()

    @classmethod
    def get_account_by_id(cls, account_id):
        return cls.account_dao.get_account(account_id)

    @classmethod
    def update_account(cls, account):
        return cls.account_dao.update_account(account)

    @classmethod
    def delete_account(cls, account_id):
        return cls.account_dao.delete_account(account_id)

    @classmethod
    def deposit_amount(cls, account_id, client_id):
        try:
            acct = cls.account_dao.get_account(account_id, client_id)
            amount: float
            acct.account_balance += amount
            cls.update_account(acct, client_id)
            return acct.account_balance
        except ResourceUnavailable as e:
            return "The client or account exists", 404
        except ResourceNotFound as r:
            return "There is not enough found", 422

    @classmethod
    def withdraw_amount(cls, account_id, client_id):
        try:
            acct = cls.account_dao.get_account(account_id, client_id)
            amount: float
            acct.account_balance -= amount
            cls.update_account(acct, client_id)
            return acct.account_balance
        except ResourceUnavailable as e:
            return "The client or account exists", 404
        except ResourceNotFound as r:
            return "There is not enough found", 422
Beispiel #11
0
 def deposit_into_account(cls, client_id, account_id, amount):
     return AccountDAOImpl.deposit_into_account(int(client_id),
                                                int(account_id),
                                                int(amount))
Beispiel #12
0
 def withdraw_from_account(cls, client_id, account_id, amount):
     return AccountDAOImpl.withdraw_from_account(int(client_id),
                                                 int(account_id),
                                                 int(amount))
Beispiel #13
0
    def delete_account_with_id(cls, client_id, account_id):

        return AccountDAOImpl.delete_account_with_id(int(client_id),
                                                     int(account_id))
 def test_update_account_with_id(self):
     assert AccountDAOImpl.update_account_with_id(1, 13, 900)
 def test_delete_account_with_id(self):
     assert AccountDAOImpl.delete_account_with_id(1, 15)
 def test_withdraw_from_account(self):
     assert AccountDAOImpl.withdraw_from_account(1, 5, 10)
 def test_deposit_into_account(self):
     assert AccountDAOImpl.deposit_into_account(1, 3, 40)
 def test_get_account_with_id(self):
     assert AccountDAOImpl.get_account_with_id(1, 13)
Beispiel #19
0
 def transfer_funds(cls, client_id, account_idw, account_idd, amount):
     return AccountDAOImpl.transfer_funds(int(client_id), int(account_idw),
                                          int(account_idd), int(amount))
 def test_transfer_funds(self):
     assert AccountDAOImpl.transfer_funds(1, 4, 16)
 def test_get_all_accounts_for_client(self):
     assert AccountDAOImpl.get_account_with_id(1, 2)
 def test_create_account(self):
     assert AccountDAOImpl.create_account(1, 100)
Beispiel #23
0
 def create_account(cls, client_id, amount):
     return AccountDAOImpl.create_account(int(client_id), int(amount))
 def test_get_all_accounts_in_range(self):
     assert AccountDAOImpl.get_all_accounts_in_range(1, 0, 5000)