Skip to content

Commit

Permalink
Merge pull request #117 from KOSASIH/deepsource-transform-2d706e54
Browse files Browse the repository at this point in the history
style: format code with Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf
  • Loading branch information
KOSASIH authored May 10, 2024
2 parents d3a2509 + 17168bf commit b1f7408
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions banking/transaction_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import logging


def deposit(account_id: int, amount: float) -> bool:
"""
Deposit an amount into an account.
Expand All @@ -18,13 +19,14 @@ def deposit(account_id: int, amount: float) -> bool:
account = get_account_by_id(account_id)
if amount < 0:
raise ValueError("Amount cannot be negative")
account['balance'] += amount
account["balance"] += amount
save_account(account)
return True
except Exception as e:
logging.error(f"Error depositing into account {account_id}: {e}")
return False


def withdraw(account_id: int, amount: float) -> bool:
"""
Withdraw an amount from an account.
Expand All @@ -41,15 +43,16 @@ def withdraw(account_id: int, amount: float) -> bool:
account = get_account_by_id(account_id)
if amount < 0:
raise ValueError("Amount cannot be negative")
if account['balance'] < amount:
if account["balance"] < amount:
raise ValueError("Insufficient balance")
account['balance'] -= amount
account["balance"] -= amount
save_account(account)
return True
except Exception as e:
logging.error(f"Error withdrawing from account {account_id}: {e}")
return False


def transfer(from_account_id: int, to_account_id: int, amount: float) -> bool:
"""
Transfer an amount between two accounts.
Expand All @@ -63,7 +66,9 @@ def transfer(from_account_id: int, to_account_id: int, amount: float) -> bool:
bool: True if the transfer was successful, False otherwise.
"""
try:
logging.info(f"Transferring {amount} from account {from_account_id} to account {to_account_id}")
logging.info(
f"Transferring {amount} from account {from_account_id} to account {to_account_id}"
)
if not withdraw(from_account_id, amount):
return False
if not deposit(to_account_id, amount):
Expand Down

0 comments on commit b1f7408

Please sign in to comment.