Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ public class DecisionTakenEvent extends Event<DecisionTakenEventPayload> {

public static final String TYPE = "ASSET_DECISION_TAKEN";

private DecisionTakenEvent(Id aggregateId, DecisionTakenEventPayload payload) {
super(aggregateId, TYPE, payload);
private DecisionTakenEvent(Id aggregateId, DecisionTakenEventPayload payload, int version) {
super(aggregateId, TYPE, payload, version);
}

protected DecisionTakenEvent(EventId id,
Expand All @@ -22,14 +22,15 @@ protected DecisionTakenEvent(EventId id,
super(id, decisionId, TYPE, payload, occurredAt, version);
}

public static DecisionTakenEvent with(DecisionId decisionId, AssetId assetId, Date date, Type type, RiskLevel riskLevel) {
public static DecisionTakenEvent with(DecisionId decisionId, AssetId assetId, Date date, Type type,
RiskLevel riskLevel, int version) {
DecisionTakenEventPayload payload = new DecisionTakenEventPayload(
assetId.value(),
date,
type.name(),
riskLevel.value()
);
return new DecisionTakenEvent(decisionId, payload);
return new DecisionTakenEvent(decisionId, payload, version);
}

public static DecisionTakenEvent hydrate(EventId id,
Expand Down
4 changes: 0 additions & 4 deletions src/main/java/io/autoinvestor/domain/events/Event.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ public abstract class Event<P extends EventPayload> {
private final Date occurredAt;
private final int version;

protected Event(Id aggregateId, String type, P payload) {
this(aggregateId, type, payload, 1);
}

protected Event(Id aggregateId, String type, P payload, int version) {
this.id = EventId.generate();
this.aggregateId = aggregateId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

public abstract class EventSourcedEntity {
private final List<Event<?>> appliedEvents = new ArrayList<>();
private int version;
protected int version;

protected EventSourcedEntity(List<Event<?>> stream) {
if (!stream.isEmpty()) {
Expand All @@ -18,10 +18,6 @@ protected EventSourcedEntity(List<Event<?>> stream) {
}
}

protected EventSourcedEntity() {
this(null);
}

protected void apply(Event<?> e) {
appliedEvents.add(e);
when(e);
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/io/autoinvestor/domain/model/Decision.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ public void takeDecision(String assetId, int feelingInt, RiskLevel riskLevel) {
AssetId.of(assetId),
new Date(),
type,
riskLevel
riskLevel,
this.version
));
}

Expand Down