class ToTransfer(): def __init__(self): #unitofwork is better? self.__session = Session() self.__bankaccountrepository = BankAccountRepository(self.__session) self.__banktransactionrecordrepository = BankTransactionRecordRepository( self.__session) def execute(self, senderaccountnumber, receiveraccountnumber, transferamount): #Validar targetaccountnumber transferamount = Amount(transferamount) senderaccount = self.__bankaccountrepository.findperaccountnumber( senderaccountnumber) receiveraccount = self.__bankaccountrepository.findperaccountnumber( receiveraccountnumber) banktransfer = BankTransfer(senderaccount, receiveraccount, transferamount) banktransactionrecords = banktransfer.transfer() self.__bankaccountrepository.update(senderaccount) self.__bankaccountrepository.update(receiveraccount) self.__banktransactionrecordrepository.addmultiple( banktransactionrecords) self.__session.commit()
class CreateBankAccount(): def __init__(self): #unitofwork is better? self.__session = Session() self.__bankaccountrepository = BankAccountRepository(self.__session) def execute(self, balance, accounttype): number = str(random.randint(1, 999999999999999999)) balance = Amount(balance) accounttype = AccountType(accounttype) newbankaccount = BankAccount(number, balance, accounttype) self.__bankaccountrepository.add(newbankaccount) self.__session.commit()
class ToDeposit(): def __init__(self): #unitofwork is better? self.__session = Session() self.__bankaccountrepository = BankAccountRepository(self.__session) self.__banktransactionrecordrepository = BankTransactionRecordRepository( self.__session) def execute(self, receiveraccountnumber, depositamount): #Validar targetaccountnumber depositamount = Amount(depositamount) receiveraccount = self.__bankaccountrepository.findperaccountnumber( receiveraccountnumber) bankdeposit = BankDeposit(receiveraccount, depositamount) banktransactionrecord = bankdeposit.todeposit() self.__bankaccountrepository.update(receiveraccount) self.__banktransactionrecordrepository.add(banktransactionrecord) self.__session.commit()
class ToWithdraw(): def __init__(self): #unitofwork is better? self.__session = Session() self.__bankaccountrepository = BankAccountRepository(self.__session) self.__banktransactionrecordrepository = BankTransactionRecordRepository( self.__session) def execute(self, targetaccountnumber, withdrawamount): #Validar targetaccountnumber withdrawamount = Amount(withdrawamount) targetaccount = self.__bankaccountrepository.findperaccountnumber( targetaccountnumber) bankdraft = BankDraft(targetaccount, withdrawamount) banktransactionrecord = bankdraft.towithdraw() self.__bankaccountrepository.update(targetaccount) self.__banktransactionrecordrepository.add(banktransactionrecord) self.__session.commit()
def __init__(self): #unitofwork is better? self.__session = Session() self.__bankaccountrepository = BankAccountRepository(self.__session) self.__banktransactionrecordrepository = BankTransactionRecordRepository( self.__session)
def __init__(self): #unitofwork is better? self.__session = Session() self.__bankaccountrepository = BankAccountRepository(self.__session)