From 7e58a17e35fad6691ae259223bfd892b7cfd4b35 Mon Sep 17 00:00:00 2001 From: Fady Salama Date: Fri, 24 Nov 2023 15:05:17 +0100 Subject: [PATCH 1/4] add domain --- domain/bankaccount.py | 14 ++++++++++++++ domain/repository.py | 24 ++++++++++++++++++++++++ domain/user.py | 9 +++++++++ 3 files changed, 47 insertions(+) create mode 100644 domain/bankaccount.py create mode 100644 domain/repository.py create mode 100644 domain/user.py 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..248f0cd --- /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): + 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 + From d808cf9e9c2ebef41b897c5e058ce69d116c9f24 Mon Sep 17 00:00:00 2001 From: Fady Salama Date: Fri, 24 Nov 2023 15:14:06 +0100 Subject: [PATCH 2/4] fix --- domain/repository.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/domain/repository.py b/domain/repository.py index 248f0cd..2998c43 100644 --- a/domain/repository.py +++ b/domain/repository.py @@ -16,7 +16,7 @@ def getBankAccount(self, user: User): pass @abstractmethod - def updateBankAccount(self, user: User): + def updateBankAccount(self, user: User, new_balance: float): pass @abstractmethod From f4a69c8209fc02c25075cdc86ae9e5617d4c3e4e Mon Sep 17 00:00:00 2001 From: Fady Salama Date: Fri, 24 Nov 2023 15:14:29 +0100 Subject: [PATCH 3/4] add application --- application/donatingService.py | 12 ++++++++++++ application/loaningService.py | 0 application/withdrawingService.py | 12 ++++++++++++ 3 files changed, 24 insertions(+) create mode 100644 application/donatingService.py create mode 100644 application/loaningService.py create mode 100644 application/withdrawingService.py 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 From 9f8297487e90c49aad367fe68757899277366306 Mon Sep 17 00:00:00 2001 From: Fady Salama Date: Fri, 24 Nov 2023 15:17:53 +0100 Subject: [PATCH 4/4] add infrastructure --- infrastructure/sqlrepository.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 infrastructure/sqlrepository.py 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