transfer money operation

This commit is contained in:
Michal Zeman
2019-12-14 11:51:46 +01:00
parent 65381f7f50
commit edf063d0c4
72 changed files with 1421 additions and 276 deletions

View File

@@ -1,5 +1,6 @@
package com.mz.reactor.ddd.common.api;
import com.fasterxml.jackson.annotation.JsonInclude;
import org.immutables.value.Value;
import java.time.Instant;
@@ -7,6 +8,7 @@ import java.util.Optional;
public interface Message {
@JsonInclude(JsonInclude.Include.NON_EMPTY)
Optional<String> correlationId();
@Value.Default

View File

@@ -5,6 +5,6 @@ import com.mz.reactor.ddd.common.api.event.DomainEvent;
@FunctionalInterface
public interface CommandHandler<A, C extends Command> {
<E extends DomainEvent> CommandResult<E> execute(A aggregate, C command);
CommandResult execute(A aggregate, C command);
}

View File

@@ -8,20 +8,20 @@ import java.util.Optional;
import java.util.UUID;
@Value.Immutable
public interface CommandResult<E extends DomainEvent> {
public interface CommandResult {
enum StatusCode {
OK,
BAD_COMMAND,
FAILED,
NOT_MODIFIED;
NOT_MODIFIED
}
String commandId();
StatusCode statusCode();
List<E> events();
List<? extends DomainEvent> events();
Optional<RuntimeException> error();
@@ -29,23 +29,24 @@ public interface CommandResult<E extends DomainEvent> {
return ImmutableCommandResult.builder();
}
static <D extends DomainEvent> CommandResult<D> fromError(RuntimeException error, D event, Command command) {
static CommandResult fromError(RuntimeException error, List<? extends DomainEvent> events, Command command) {
return builder()
.commandId(Optional.ofNullable(command)
.map(Command::commandId)
.orElseGet(() -> UUID.randomUUID().toString()))
.statusCode(StatusCode.BAD_COMMAND)
.events(Optional.ofNullable(event).map(List::of).orElseGet(List::of))
.statusCode(StatusCode.FAILED)
.events(events)
.error(error)
.build();
}
static <D extends DomainEvent> CommandResult<D> badCommand(Command cmd) {
static CommandResult badCommand(Command cmd) {
return builder()
.commandId(Optional.ofNullable(cmd)
.map(Command::commandId)
.orElseGet(() -> UUID.randomUUID().toString()))
.statusCode(StatusCode.BAD_COMMAND)
.events(List.of())
.build();
}

View File

@@ -1,8 +1,8 @@
package com.mz.reactor.ddd.common.api.event;
@FunctionalInterface
public interface EventApplier<A, E extends DomainEvent> {
public interface EventApplier<A> {
A apply(A aggregate, E event);
<E extends DomainEvent> A apply(A aggregate, E event);
}

View File

@@ -5,10 +5,7 @@ public class Id extends StringValue {
super(value);
}
@Override
public String toString() {
return "Id{" +
"value='" + value + '\'' +
'}';
public static Id of(String id) {
return new Id(id);
}
}

View File

@@ -1,5 +1,9 @@
package com.mz.reactor.ddd.common.api.view;
public interface DomainView {
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.mz.reactor.ddd.common.api.event.DomainEvent;
public interface DomainView extends DomainEvent {
@JsonIgnore
String id();
}