diff --git a/application/donatingService.py b/application/donatingService.py new file mode 100644 index 0000000..f4d9790 --- /dev/null +++ b/application/donatingService.py @@ -0,0 +1,12 @@ +class DonatingService: + + def __init__(self): + return self + + def donate_from_user1_to_user2(self, repository: Repository, user1: User, user2: User, amount: float): + balance_1 = repository.getBalance(user=user1) + balance_2 = repository.getBalance(user=user2) + new_balance1 = balance_1 - amount + new_balance2 = balance_1 + amount + repository.updateBankAccount(user=user1, new_balance=new_balance1) + repository.updateBankAccount(user=user2, new_balance=new_balance2) \ No newline at end of file diff --git a/application/loaningService.py b/application/loaningService.py new file mode 100644 index 0000000..e69de29 diff --git a/application/withdrawingService.py b/application/withdrawingService.py new file mode 100644 index 0000000..b84a682 --- /dev/null +++ b/application/withdrawingService.py @@ -0,0 +1,12 @@ +from domain.repository import Repository +from domain.user import User + +class WithdrawingService: + + def __init__(self): + return self + + def withdraw_from_user(self, repository: Repository, user: User, amount: float): + balance = repository.getBalance(user=user) + new_balance = balance - amount + repository.updateBankAccount(user=user, new_balance=new_balance) \ No newline at end of file diff --git a/domain/bankaccount.py b/domain/bankaccount.py new file mode 100644 index 0000000..0086c8b --- /dev/null +++ b/domain/bankaccount.py @@ -0,0 +1,14 @@ +from user import User + +class BankAccount: + _balance: float + _user: User + def __init__(self, user: User): + self._balance = 0 + self._user = user + def getBalance(self): + return self._balance + def setBalance(self, new_balance: float): + self._balance = new_balance + def getUser(self): + return self._user \ No newline at end of file diff --git a/domain/repository.py b/domain/repository.py new file mode 100644 index 0000000..2998c43 --- /dev/null +++ b/domain/repository.py @@ -0,0 +1,24 @@ +from abc import ABC, abstractmethod +from bankaccount import BankAccount +from user import User + +class Repository(ABC): + @abstractmethod + def __init__(): + pass + + @abstractmethod + def addBankAccount(self, BankAccount): + pass + + @abstractmethod + def getBankAccount(self, user: User): + pass + + @abstractmethod + def updateBankAccount(self, user: User, new_balance: float): + pass + + @abstractmethod + def getBalance(self, user: User): + pass \ No newline at end of file diff --git a/domain/user.py b/domain/user.py new file mode 100644 index 0000000..5d95e85 --- /dev/null +++ b/domain/user.py @@ -0,0 +1,9 @@ +class User: + _name: str + def __init__(self, name: str): + self._name = name + def getName(self): + return self._name + def setName(self, name): + self._name = name + diff --git a/infrastructure/sqlrepository.py b/infrastructure/sqlrepository.py new file mode 100644 index 0000000..5d17054 --- /dev/null +++ b/infrastructure/sqlrepository.py @@ -0,0 +1,15 @@ +from domain.repository import Repository + +class SqLRepository(Repository): + + def addBankAccount(self, BankAccount): + pass + + def getBankAccount(self, user: User): + pass + + def updateBankAccount(self, user: User, new_balance: float): + pass + + def getBalance(self, user: User): + pass \ No newline at end of file