diff --git a/src/MPWAR/Module/Economy/Domain/AccountRepository.php b/src/MPWAR/Module/Economy/Domain/AccountRepository.php index 927441d..0a3168b 100644 --- a/src/MPWAR/Module/Economy/Domain/AccountRepository.php +++ b/src/MPWAR/Module/Economy/Domain/AccountRepository.php @@ -17,4 +17,11 @@ public function add(Account $account); * @return Account|null */ public function search(AccountOwner $owner); + + /** + * @param Account $account + * + * @return void + */ + public function save(Account $account); } diff --git a/src/MPWAR/Module/Economy/Infrastructure/Persistence/AccountRepositoryInMemory.php b/src/MPWAR/Module/Economy/Infrastructure/Persistence/AccountRepositoryInMemory.php index a3be7cb..e0261ae 100644 --- a/src/MPWAR/Module/Economy/Infrastructure/Persistence/AccountRepositoryInMemory.php +++ b/src/MPWAR/Module/Economy/Infrastructure/Persistence/AccountRepositoryInMemory.php @@ -18,11 +18,21 @@ public function __construct() public function add(Account $account) { - $this->accounts->set($account->owner()->value(), $account); + $this->persist($account); } public function search(AccountOwner $owner) { return $this->accounts->get($owner->value()); } + + public function save(Account $account) + { + $this->persist($account); + } + + private function persist(Account $account) + { + $this->accounts->set($account->owner()->value(), $account); + } } diff --git a/src/MPWAR/Module/Economy/Infrastructure/Persistence/AccountRepositoryMySql.php b/src/MPWAR/Module/Economy/Infrastructure/Persistence/AccountRepositoryMySql.php index d9604f5..06bf5f3 100644 --- a/src/MPWAR/Module/Economy/Infrastructure/Persistence/AccountRepositoryMySql.php +++ b/src/MPWAR/Module/Economy/Infrastructure/Persistence/AccountRepositoryMySql.php @@ -18,8 +18,7 @@ public function __construct(EntityManager $entityManager) public function add(Account $account) { - $this->entityManager->persist($account); - $this->entityManager->flush($account); + $this->persist($account); } public function search(AccountOwner $owner) @@ -27,6 +26,17 @@ public function search(AccountOwner $owner) return $this->repository()->find($owner); } + public function save(Account $account) + { + $this->persist($account); + } + + protected function persist(Account $account) + { + $this->entityManager->persist($account); + $this->entityManager->flush($account); + } + private function repository() { return $this->entityManager->getRepository(Account::class);