Ejemplo n.º 1
0
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
Ejemplo n.º 2
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
Ejemplo n.º 3
0
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)
Ejemplo n.º 4
0
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
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
Ejemplo n.º 6
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