Account aggregate contract definition
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
package com.mz.reactor.ddd.reactorddd.domain;
|
||||
package com.mz.reactor.ddd.reactorddd.account.domain;
|
||||
|
||||
import com.mz.reactor.ddd.common.api.valueobject.Id;
|
||||
import com.mz.reactor.ddd.common.api.valueobject.Money;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.mz.reactor.ddd.reactorddd.domain;
|
||||
package com.mz.reactor.ddd.reactorddd.account.domain;
|
||||
|
||||
import org.immutables.value.Value;
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.mz.reactor.ddd.reactorddd.account.domain.command;
|
||||
|
||||
import com.mz.reactor.ddd.common.api.command.Command;
|
||||
|
||||
public interface AccountCommand extends Command {
|
||||
|
||||
String aggregateId();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package com.mz.reactor.ddd.reactorddd.account.domain.command;
|
||||
|
||||
import com.mz.reactor.ddd.common.api.command.CommandHandler;
|
||||
import com.mz.reactor.ddd.common.api.command.CommandResult;
|
||||
import com.mz.reactor.ddd.reactorddd.account.domain.AccountAggregate;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
public class AccountCommandHandler implements CommandHandler<AccountAggregate, AccountCommand> {
|
||||
|
||||
private final Map<Class, BiFunction> handlers = new HashMap<>();
|
||||
|
||||
public AccountCommandHandler() {
|
||||
addHandler(CreateAccount.class, this::doCreateAccount);
|
||||
addHandler(WithdrawMoney.class, this::doWithdrawMoney);
|
||||
addHandler(DepositMoney.class, this::doDepositMoney);
|
||||
}
|
||||
|
||||
private <K extends AccountCommand> void addHandler(
|
||||
Class<K> kClass,
|
||||
BiFunction<AccountAggregate, K, CommandResult> handler
|
||||
) {
|
||||
this.handlers.put(kClass, handler);
|
||||
}
|
||||
|
||||
private CommandResult doWithdrawMoney(AccountAggregate aggregate, WithdrawMoney command) {
|
||||
return null;
|
||||
}
|
||||
|
||||
private CommandResult doCreateAccount(AccountAggregate aggregate, CreateAccount command) {
|
||||
return null;
|
||||
}
|
||||
|
||||
private CommandResult doDepositMoney(AccountAggregate aggregate, DepositMoney command) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(AccountAggregate aggregate, AccountCommand command) {
|
||||
return (CommandResult) handlers.get(command.getClass()).apply(aggregate, command);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.mz.reactor.ddd.reactorddd.account.domain.command;
|
||||
|
||||
import org.immutables.value.Value;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@Value.Immutable
|
||||
public interface CreateAccount extends AccountCommand {
|
||||
|
||||
BigDecimal balance();
|
||||
|
||||
static ImmutableCreateAccount.Builder builder() {
|
||||
return ImmutableCreateAccount.builder();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.mz.reactor.ddd.reactorddd.account.domain.command;
|
||||
|
||||
import org.immutables.value.Value;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@Value.Immutable
|
||||
public interface DepositMoney extends AccountCommand {
|
||||
BigDecimal amount();
|
||||
|
||||
static ImmutableDepositMoney.Builder builder() {
|
||||
return ImmutableDepositMoney.builder();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.mz.reactor.ddd.reactorddd.account.domain.command;
|
||||
|
||||
import org.immutables.value.Value;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@Value.Immutable
|
||||
public interface WithdrawMoney extends AccountCommand {
|
||||
|
||||
BigDecimal amount();
|
||||
|
||||
static ImmutableWithdrawMoney.Builder builder() {
|
||||
return ImmutableWithdrawMoney.builder();
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,13 @@
|
||||
package com.mz.reactor.ddd.reactorddd.domain.event;
|
||||
package com.mz.reactor.ddd.reactorddd.account.domain.event;
|
||||
|
||||
import org.immutables.value.Value;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@Value.Immutable
|
||||
public interface AccountCreated extends AccountEvent {
|
||||
|
||||
BigDecimal balance();
|
||||
|
||||
static ImmutableAccountCreated.Builder builder() {
|
||||
return ImmutableAccountCreated.builder();
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.mz.reactor.ddd.reactorddd.domain.event;
|
||||
package com.mz.reactor.ddd.reactorddd.account.domain.event;
|
||||
|
||||
import com.mz.reactor.ddd.common.api.event.DomainEvent;
|
||||
import org.immutables.value.Value;
|
||||
|
||||
public interface AccountEvent extends DomainEvent {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.mz.reactor.ddd.reactorddd.domain.event;
|
||||
package com.mz.reactor.ddd.reactorddd.account.domain.event;
|
||||
|
||||
import com.mz.reactor.ddd.common.api.event.EventApplier;
|
||||
import com.mz.reactor.ddd.reactorddd.domain.AccountAggregate;
|
||||
import com.mz.reactor.ddd.reactorddd.account.domain.AccountAggregate;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.mz.reactor.ddd.reactorddd.account.domain.event;
|
||||
|
||||
import org.immutables.value.Value;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@Value.Immutable
|
||||
public interface DepositMoneyFailed extends AccountEvent {
|
||||
|
||||
BigDecimal amount();
|
||||
|
||||
static ImmutableDepositMoneyFailed.Builder builder() {
|
||||
return ImmutableDepositMoneyFailed.builder();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.mz.reactor.ddd.reactorddd.account.domain.event;
|
||||
|
||||
import org.immutables.value.Value;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@Value.Immutable
|
||||
public interface MoneyDeposited extends AccountEvent {
|
||||
BigDecimal amount();
|
||||
|
||||
static ImmutableMoneyDeposited.Builder builder() {
|
||||
return ImmutableMoneyDeposited.builder();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.mz.reactor.ddd.reactorddd.account.domain.event;
|
||||
|
||||
import org.immutables.value.Value;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@Value.Immutable
|
||||
public interface MoneyWithdrawn extends AccountEvent {
|
||||
BigDecimal amount();
|
||||
|
||||
static ImmutableMoneyWithdrawn.Builder builder() {
|
||||
return ImmutableMoneyWithdrawn.builder();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.mz.reactor.ddd.reactorddd.account.domain.event;
|
||||
|
||||
import org.immutables.value.Value;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@Value.Immutable
|
||||
public interface WithdrawMoneyFailed extends AccountEvent {
|
||||
|
||||
BigDecimal amount();
|
||||
|
||||
static ImmutableWithdrawMoneyFailed.Builder builder() {
|
||||
return ImmutableWithdrawMoneyFailed.builder();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
package com.mz.reactor.ddd.reactorddd.domain.event;
|
||||
|
||||
public interface DepositMoneyFailed extends AccountEvent {
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
package com.mz.reactor.ddd.reactorddd.domain.event;
|
||||
|
||||
public interface MoneyDeposited extends AccountEvent {
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
package com.mz.reactor.ddd.reactorddd.domain.event;
|
||||
|
||||
public interface MoneyWithdrawn extends AccountEvent {
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
package com.mz.reactor.ddd.reactorddd.domain.event;
|
||||
|
||||
public interface WithdrawMoneyFailed extends AccountEvent {
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.mz.reactor.ddd.reactorddd.transaction.domain;
|
||||
|
||||
import com.mz.reactor.ddd.common.api.valueobject.Id;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
public class TransactionAggregate {
|
||||
|
||||
enum TransactionState {
|
||||
Created,
|
||||
Finished,
|
||||
Failed
|
||||
}
|
||||
|
||||
private Id aggregateId;
|
||||
|
||||
private Id fromAccount;
|
||||
|
||||
private Id toAccount;
|
||||
|
||||
private BigDecimal amount;
|
||||
|
||||
public TransactionAggregate(String aggregateId) {
|
||||
this.aggregateId = new Id(aggregateId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.mz.reactor.ddd.reactorddd.transaction.domain;
|
||||
|
||||
import org.immutables.value.Value;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@Value.Immutable
|
||||
public interface TransactionState {
|
||||
|
||||
String aggregateId();
|
||||
|
||||
String fromAccountId();
|
||||
|
||||
String toAccountId();
|
||||
|
||||
BigDecimal amount();
|
||||
|
||||
static ImmutableTransactionState.Builder builder() {
|
||||
return ImmutableTransactionState.builder();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.mz.reactor.ddd.reactorddd.transaction.domain.command;
|
||||
|
||||
import org.immutables.value.Value;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@Value.Immutable
|
||||
public interface CreateTransaction extends TransactionCommand {
|
||||
String aggregateId();
|
||||
|
||||
String fromAccountId();
|
||||
|
||||
String toAccountId();
|
||||
|
||||
BigDecimal amount();
|
||||
|
||||
static ImmutableCreateTransaction.Builder builder() {
|
||||
return ImmutableCreateTransaction.builder();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package com.mz.reactor.ddd.reactorddd.transaction.domain.command;
|
||||
|
||||
import com.mz.reactor.ddd.common.api.command.Command;
|
||||
|
||||
public interface TransactionCommand extends Command {
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.mz.reactor.ddd.reactorddd.transaction.domain.command;
|
||||
|
||||
import com.mz.reactor.ddd.common.api.command.CommandHandler;
|
||||
import com.mz.reactor.ddd.common.api.command.CommandResult;
|
||||
import com.mz.reactor.ddd.reactorddd.transaction.domain.TransactionAggregate;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
public class TransactionCommandHandler implements CommandHandler<TransactionAggregate, TransactionCommand> {
|
||||
|
||||
private final Map<Class, BiFunction> handlers = new HashMap<>();
|
||||
|
||||
public TransactionCommandHandler() {
|
||||
addHandler(CreateTransaction.class, this::doCreateTransaction);
|
||||
}
|
||||
|
||||
private <C extends TransactionCommand> void addHandler(
|
||||
Class<C> kClass,
|
||||
BiFunction<TransactionAggregate, C, CommandResult> handler
|
||||
) {
|
||||
handlers.put(kClass, handler);
|
||||
}
|
||||
|
||||
private CommandResult doCreateTransaction(TransactionAggregate aggregate, CreateTransaction command) {
|
||||
return (CommandResult) handlers.get(command).apply(aggregate, command);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(TransactionAggregate aggregate, TransactionCommand command) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.mz.reactor.ddd.reactorddd.transaction.domain.event;
|
||||
|
||||
import org.immutables.value.Value;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@Value.Immutable
|
||||
public interface TransactionCreated extends TransactionEvent {
|
||||
|
||||
String fromAccountId();
|
||||
|
||||
String toAccountId();
|
||||
|
||||
BigDecimal amount();
|
||||
|
||||
static ImmutableTransactionCreated.Builder builder() {
|
||||
return ImmutableTransactionCreated.builder();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.mz.reactor.ddd.reactorddd.transaction.domain.event;
|
||||
|
||||
import com.mz.reactor.ddd.common.api.event.DomainEvent;
|
||||
|
||||
public interface TransactionEvent extends DomainEvent {
|
||||
|
||||
String aggregateId();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.mz.reactor.ddd.reactorddd.transaction.domain.event;
|
||||
|
||||
import org.immutables.value.Value;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@Value.Immutable
|
||||
public interface TransactionFailed extends TransactionEvent {
|
||||
|
||||
String fromAccountId();
|
||||
|
||||
String toAccountId();
|
||||
|
||||
BigDecimal amount();
|
||||
|
||||
static ImmutableTransactionFailed.Builder builder() {
|
||||
return ImmutableTransactionFailed.builder();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.mz.reactor.ddd.reactorddd.transaction.domain.event;
|
||||
|
||||
import org.immutables.value.Value;
|
||||
|
||||
@Value.Immutable
|
||||
public interface TransactionFinished extends TransactionEvent {
|
||||
|
||||
static ImmutableTransactionFinished.Builder builder() {
|
||||
return ImmutableTransactionFinished.builder();
|
||||
}
|
||||
}
|
||||
@@ -68,6 +68,7 @@ project(':bank-account:bank-account-application') {
|
||||
dependencies {
|
||||
implementation 'org.springframework.boot:spring-boot-starter-webflux'
|
||||
implementation project(':bank-account:account-domain')
|
||||
implementation project(':bank-account:transaction-domain')
|
||||
testImplementation 'org.springframework.boot:spring-boot-starter-test'
|
||||
testImplementation 'io.projectreactor:reactor-test'
|
||||
}
|
||||
@@ -79,7 +80,11 @@ project(':bank-account:account-domain') {
|
||||
}
|
||||
}
|
||||
|
||||
project(':bank-account:transaction-domain') {}
|
||||
project(':bank-account:transaction-domain') {
|
||||
dependencies {
|
||||
api project(':common-api')
|
||||
}
|
||||
}
|
||||
|
||||
project(':shared-dependencies') {
|
||||
dependencies {
|
||||
|
||||
@@ -5,7 +5,6 @@ import org.immutables.value.Value;
|
||||
import java.time.Instant;
|
||||
import java.util.Optional;
|
||||
|
||||
@Value.Immutable
|
||||
public interface Command {
|
||||
|
||||
Optional<String> correlationId();
|
||||
|
||||
BIN
intellij-settings-export/live-templates.zip
Normal file
BIN
intellij-settings-export/live-templates.zip
Normal file
Binary file not shown.
Reference in New Issue
Block a user