Skip to content

Commit

Permalink
Merge pull request #100 from KOSASIH/deepsource-transform-e88e4dc5
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 9ce2191 + 0ef9b2f commit 7cc62f1
Showing 1 changed file with 6 additions and 36 deletions.
42 changes: 6 additions & 36 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 @@ -13,17 +14,8 @@ def deposit(account_id: int, amount: float) -> bool:
Returns:
bool: True if the deposit was successful, False otherwise.
"""
try:
logging.info(f"Depositing {amount} into account {account_id}")
account = get_account_by_id(account_id)
if amount < 0:
raise ValueError("Amount cannot be negative")
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:
"""
Expand All @@ -36,19 +28,8 @@ def withdraw(account_id: int, amount: float) -> bool:
Returns:
bool: True if the withdrawal was successful, False otherwise.
"""
try:
logging.info(f"Withdrawing {amount} from account {account_id}")
account = get_account_by_id(account_id)
if amount < 0:
raise ValueError("Amount cannot be negative")
if account['balance'] < amount:
raise ValueError("Insufficient balance")
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:
"""
Expand All @@ -62,15 +43,4 @@ def transfer(from_account_id: int, to_account_id: int, amount: float) -> bool:
Returns:
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}")
if not withdraw(from_account_id, amount):
return False
if not deposit(to_account_id, amount):
# Rollback the withdrawal if deposit fails
deposit(from_account_id, amount)
return False
return True
except Exception as e:
logging.error(f"Error transferring between accounts: {e}")
return False

0 comments on commit 7cc62f1

Please sign in to comment.