-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#44 - Refactoring - Driver Ports with plain DTOs - Driven Ports with …
…primitives and DTOs
- Loading branch information
1 parent
273ed83
commit 71725a2
Showing
51 changed files
with
513 additions
and
396 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
src/main/java/com/optivem/kata/banking/core/acl/BankAccountConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package com.optivem.kata.banking.core.acl; | ||
|
||
import com.optivem.kata.banking.core.domain.accounts.*; | ||
import com.optivem.kata.banking.core.ports.driven.BankAccountDto; | ||
|
||
public class BankAccountConverter { | ||
public static BankAccount toEntity(BankAccountDto dto) { | ||
var accountId = AccountId.of(dto.getAccountId()); | ||
var accountNumber = AccountNumber.of(dto.getAccountNumber()); | ||
var accountHolderName = AccountHolderName.of(dto.getFirstName(), dto.getLastName()); | ||
var openingDate = dto.getOpeningDate(); | ||
var balance = Balance.of(dto.getBalance()); | ||
|
||
return new BankAccount(accountId, accountNumber, accountHolderName, openingDate, balance); | ||
} | ||
|
||
public static BankAccountDto toDto(BankAccount bankAccount) { | ||
var accountId = bankAccount.getAccountId().toLong(); | ||
var accountNumber = bankAccount.getAccountNumber().toString(); | ||
var firstName = bankAccount.getAccountHolderName().firstName().toString(); | ||
var lastName = bankAccount.getAccountHolderName().lastName().toString(); | ||
var openingDate = bankAccount.getOpeningDate(); | ||
var balance = bankAccount.getBalance().toInt(); | ||
|
||
var dto = new BankAccountDto(); | ||
dto.setAccountId(accountId); | ||
dto.setAccountNumber(accountNumber); | ||
dto.setFirstName(firstName); | ||
dto.setLastName(lastName); | ||
dto.setOpeningDate(openingDate); | ||
dto.setBalance(balance); | ||
|
||
return dto; | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
src/main/java/com/optivem/kata/banking/core/acl/BankAccountRepositoryImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package com.optivem.kata.banking.core.acl; | ||
|
||
import com.optivem.kata.banking.core.domain.accounts.AccountId; | ||
import com.optivem.kata.banking.core.domain.accounts.AccountNumber; | ||
import com.optivem.kata.banking.core.domain.accounts.BankAccount; | ||
import com.optivem.kata.banking.core.domain.accounts.BankAccountRepository; | ||
import com.optivem.kata.banking.core.ports.driven.AccountIdGenerator; | ||
import com.optivem.kata.banking.core.ports.driven.AccountNumberGenerator; | ||
import com.optivem.kata.banking.core.ports.driven.BankAccountStorage; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.Optional; | ||
|
||
@Component | ||
public class BankAccountRepositoryImpl implements BankAccountRepository { | ||
private final BankAccountStorage bankAccountStorage; | ||
private final AccountIdGenerator accountIdGenerator; | ||
private final AccountNumberGenerator accountNumberGenerator; | ||
|
||
public BankAccountRepositoryImpl(BankAccountStorage bankAccountStorage, AccountIdGenerator accountIdGenerator, AccountNumberGenerator accountNumberGenerator) { | ||
this.bankAccountStorage = bankAccountStorage; | ||
this.accountIdGenerator = accountIdGenerator; | ||
this.accountNumberGenerator = accountNumberGenerator; | ||
} | ||
|
||
@Override | ||
public Optional<BankAccount> find(AccountNumber accountNumber) { | ||
var dto = bankAccountStorage.find(accountNumber.toString()); | ||
|
||
if(dto.isEmpty()) { | ||
return Optional.empty(); | ||
} | ||
|
||
var entity = BankAccountConverter.toEntity(dto.get()); | ||
return Optional.of(entity); | ||
} | ||
|
||
@Override | ||
public void add(BankAccount bankAccount) { | ||
var dto = BankAccountConverter.toDto(bankAccount); | ||
bankAccountStorage.add(dto); | ||
} | ||
|
||
@Override | ||
public void update(BankAccount bankAccount) { | ||
var dto = BankAccountConverter.toDto(bankAccount); | ||
bankAccountStorage.update(dto); | ||
} | ||
|
||
@Override | ||
public AccountId nextAccountId() { | ||
var accountId = accountIdGenerator.next(); | ||
return AccountId.of(accountId); | ||
} | ||
|
||
@Override | ||
public AccountNumber nextAccountNumber() { | ||
var accountNumber = accountNumberGenerator.next(); | ||
return AccountNumber.of(accountNumber); | ||
} | ||
} |
7 changes: 0 additions & 7 deletions
7
src/main/java/com/optivem/kata/banking/core/domain/accounts/AccountIdGenerator.java
This file was deleted.
Oops, something went wrong.
7 changes: 0 additions & 7 deletions
7
src/main/java/com/optivem/kata/banking/core/domain/accounts/AccountNumberGenerator.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
src/main/java/com/optivem/kata/banking/core/domain/scoring/TimeFactorCalculator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 0 additions & 7 deletions
7
src/main/java/com/optivem/kata/banking/core/ports/driven/AccountIdGeneratorPort.java
This file was deleted.
Oops, something went wrong.
6 changes: 6 additions & 0 deletions
6
src/main/java/com/optivem/kata/banking/core/ports/driven/AccountNumberGenerator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.optivem.kata.banking.core.ports.driven; | ||
|
||
import com.optivem.kata.banking.core.domain.common.base.Generator; | ||
|
||
public interface AccountNumberGenerator extends Generator<String> { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 3 additions & 2 deletions
5
src/main/java/com/optivem/kata/banking/infra/fake/FakeAccountIdGenerator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
package com.optivem.kata.banking.infra.fake; | ||
|
||
import com.optivem.kata.banking.core.domain.accounts.AccountId; | ||
import com.optivem.kata.banking.core.domain.accounts.AccountIdGenerator; | ||
import com.optivem.kata.banking.core.domain.common.base.Generator; | ||
import com.optivem.kata.banking.core.ports.driven.AccountIdGenerator; | ||
import com.optivem.kata.banking.infra.fake.base.FakeGenerator; | ||
|
||
public class FakeAccountIdGenerator extends FakeGenerator<AccountId> implements AccountIdGenerator { | ||
public class FakeAccountIdGenerator extends FakeGenerator<Long> implements AccountIdGenerator { | ||
} |
5 changes: 3 additions & 2 deletions
5
src/main/java/com/optivem/kata/banking/infra/fake/FakeAccountNumberGenerator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
package com.optivem.kata.banking.infra.fake; | ||
|
||
import com.optivem.kata.banking.core.domain.accounts.AccountNumber; | ||
import com.optivem.kata.banking.core.domain.accounts.AccountNumberGenerator; | ||
import com.optivem.kata.banking.core.domain.common.base.Generator; | ||
import com.optivem.kata.banking.core.ports.driven.AccountNumberGenerator; | ||
import com.optivem.kata.banking.infra.fake.base.FakeGenerator; | ||
|
||
public class FakeAccountNumberGenerator extends FakeGenerator<AccountNumber> implements AccountNumberGenerator { | ||
public class FakeAccountNumberGenerator extends FakeGenerator<String> implements AccountNumberGenerator { | ||
} |
61 changes: 0 additions & 61 deletions
61
src/main/java/com/optivem/kata/banking/infra/fake/FakeBankAccountRepository.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.