Exemple #1
0
 def delete_client(client_id):
     try:
         ClientService.get_client_by_id(int(client_id))
         ClientService.delete_client(int(client_id))
         return 'Successfully Deleted', 205
     except ResourceNotFound as r:
         return r.message, 404
Exemple #2
0
 def get_client(client_id):
     try:
         client = ClientService.get_client_by_id(int(client_id))
         return jsonify(client.json()), 200
     except ValueError:
         return "Not a valid ID", 400  # Bad Request
     except ResourceNotFound as r:
         return r.message, 404
Exemple #3
0
    def transfer_account(client_id, account_id, account_id2):
        action = request.json['action']
        if action == 'transfer':
            try:
                ClientService.get_client_by_id(int(client_id))
                account = AccountService.get_account_by_id(int(account_id))
                account2 = AccountService.get_account_by_id(int(account_id2))

                AccountService.transfer_money(int(account_id),
                                              int(account_id2))
                return (
                    f'Successfully transferred! First Account new balance: {account.balance} Second Account new balance: {account2.balance}'
                ), 200

            except ResourceUnavailable as e:
                return e.message, 422
            except ResourceNotFound as r:
                return r.message, 404
Exemple #4
0
    def put_client_account_id(client_id, account_id):
        try:
            client_id = ClientService.get_client_by_id(int(client_id))
            AccountService.get_account_by_id(int(account_id))

            account = Account.json_parse(request.json)
            account.client_id = client_id

            account.account_id = int(account_id)
            account = AccountService.update_account(account)
            return jsonify(account.json()), 200
        except ResourceNotFound as r:
            return r.message, 404
Exemple #5
0
    def patch_account(client_id, account_id):

        action = request.json['action']
        if action == 'deposit':
            try:
                ClientService.get_client_by_id(int(client_id))
                AccountService.get_account_by_id(int(account_id))

                balance = AccountService.deposit_account(int(account_id))
                return (
                    f'Successfully deposited! New balance is: {balance}'), 200
            except ResourceNotFound as r:
                return r.message, 404

        elif action == 'withdraw':
            try:
                balance = AccountService.withdraw_account(int(account_id))
                return (
                    f'Successfully withdrawn! New balance is: {balance}'), 200
            except ResourceUnavailable as e:
                return e.message, 422
            except ResourceNotFound as r:
                return r.message, 404
Exemple #6
0
 def get_all_account(client_id):
     try:
         ClientService.get_client_by_id(int(client_id))
         return jsonify(AccountService.all_accounts(client_id)), 200
     except ResourceNotFound as r:
         return r.message, 404