def withdraw_or_deposit_client_account_with_id(client_id, account_id):
     try:
         deposit = request.get_json().get("deposit")
         withdraw = request.get_json().get('withdraw')
         print(deposit)
         if deposit and isinstance(deposit, int):
             return AccountServiceImpl.deposit_into_account(
                 client_id, account_id, deposit)
         if withdraw and isinstance(withdraw, int):
             return AccountServiceImpl.withdraw_from_account(
                 client_id, account_id, withdraw)
         raise ValueError
     except ValueError:
         return "Not a valid ID", 404
 def update_account_with_id(client_id, account_id):
     try:
         amount = request.json["amount"]
         if client_id.isdigit() and account_id.isdigit() and amount.isdigit(
         ):
             account = AccountServiceImpl.get_account_with_id(
                 client_id, account_id)
             if account == "Not a valid account":
                 return "Not a valid account", 404
             return AccountServiceImpl.update_account_with_id(
                 client_id, account_id, amount)
         else:
             raise ValueError
     except ValueError:
         return "Not a valid ID", 404
 def transfer_amount(client_id, account_id, transfer_id):
     amount = request.get_json().get('amount')
     if amount and isinstance(amount, int) and client_id.isdigit(
     ) and account_id.isdigit() and transfer_id.isdigit():
         return AccountServiceImpl.transfer_funds(client_id, account_id,
                                                  transfer_id, amount)
     else:
         return "either client or account exists", 404
 def delete_client_account_with_id(client_id, account_id):
     try:
         if client_id.isdigit() and account_id.isdigit():
             return AccountServiceImpl.delete_account_with_id(
                 client_id, account_id)
         else:
             raise ValueError
     except ValueError:
         return "Not a valid ID", 404
 def get_client_account_with_id(client_id, account_id):
     try:
         if client_id.isdigit() and account_id.isdigit():
             client = ClientServiceImpl.get_client(client_id=client_id)
             if client == "Not a valid ID":
                 return "No such client exist", 404
         return jsonify(
             AccountServiceImpl.get_account_with_id(client_id, account_id))
     except ValueError:
         return "no client exists", 404
    def get_client_accounts(client_id):
        try:
            amount_greater_than = request.args.get("amountGreaterThan")
            amount_less_than = request.args.get("amountLessThan")
            if amount_less_than and amount_greater_than:

                if amount_less_than.isdigit() and amount_greater_than.isdigit(
                ) and client_id.isdigit():
                    return jsonify(
                        AccountServiceImpl.get_all_accounts_in_range(
                            client_id, amount_less_than, amount_greater_than))
                else:
                    raise ValueError
            else:
                ret = AccountServiceImpl.get_all_accounts_for_client(client_id)
                print(ret)
                if ret == []:
                    raise ValueError
                else:
                    return jsonify(ret)
        except ValueError:
            return "no client exists", 404
    def create_client_account(client_id):
        try:
            amount = request.json["amount"]
            if client_id.isdigit():
                client = ClientServiceImpl.get_client(client_id=client_id)
                if client == "Not a valid ID":
                    return "No such client exist", 404
                if amount.isdigit():
                    print("here")
                    logging.info(f"Creating account for client id={client_id}")
                    return AccountServiceImpl.create_account(
                        client_id=client_id, amount=amount)
            else:
                raise ValueError

        except ValueError:
            return "No such client exist", 404
Example #8
0
 def test_create_account(self):
     assert AccountServiceImpl.create_account(1, 20)
Example #9
0
 def test_get_all_accounts_for_client(self):
     assert AccountServiceImpl.create_account(1, 20)
Example #10
0
 def test_deposit_into_account(self):
     assert AccountServiceImpl.deposit_into_account(1, 15, 300)
Example #11
0
 def test_transfer_funds(self):
     assert AccountServiceImpl.transfer_funds(1, 4, 3, 20)
Example #12
0
 def test_withdraw_from_account(self):
     assert AccountServiceImpl.withdraw_from_account(1, 15, 3)
Example #13
0
 def test_delete_account_with_id(self):
     assert AccountServiceImpl.delete_account_with_id(1, 3)
Example #14
0
 def test_update_account_with_id(self):
     assert AccountServiceImpl.update_account_with_id(1, 3, 500)
Example #15
0
 def test_get_account_with_id(self):
     assert AccountServiceImpl.get_account_with_id(1, 3)
Example #16
0
 def test_get_all_accounts_in_range(self):
     assert AccountServiceImpl.get_all_accounts_in_range(1, 0, 5000)