-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCalendar.java
More file actions
68 lines (58 loc) · 2.27 KB
/
Calendar.java
File metadata and controls
68 lines (58 loc) · 2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package com.dddheroes.heroesofddd.calendar.write;
import com.dddheroes.heroesofddd.calendar.write.finishday.CanOnlyFinishCurrentDay;
import com.dddheroes.heroesofddd.calendar.events.DayFinished;
import com.dddheroes.heroesofddd.calendar.write.finishday.FinishDay;
import com.dddheroes.heroesofddd.calendar.write.startday.CannotSkipDays;
import com.dddheroes.heroesofddd.calendar.events.DayStarted;
import com.dddheroes.heroesofddd.calendar.write.startday.StartDay;
import org.axonframework.commandhandling.CommandHandler;
import org.axonframework.eventsourcing.EventSourcingHandler;
import org.axonframework.modelling.command.AggregateCreationPolicy;
import org.axonframework.modelling.command.AggregateIdentifier;
import org.axonframework.modelling.command.CreationPolicy;
import org.axonframework.spring.stereotype.Aggregate;
import static org.axonframework.modelling.command.AggregateLifecycle.apply;
@Aggregate
class Calendar {
@AggregateIdentifier
private CalendarId calendarId;
private Month currentMonth;
private Week currentWeek;
private Day currentDay;
@CommandHandler
@CreationPolicy(AggregateCreationPolicy.CREATE_IF_MISSING)
// performance downside in comparison to constructor
void decide(StartDay command) {
new CannotSkipDays(command, currentMonth, currentWeek, currentDay).verify();
apply(
DayStarted.event(
command.calendarId(),
command.month(),
command.week(),
command.day()
)
);
}
@EventSourcingHandler
void evolve(DayStarted event) {
calendarId = new CalendarId(event.calendarId());
currentMonth = new Month(event.month());
currentWeek = new Week(event.week());
currentDay = new Day(event.day());
}
@CommandHandler
void decide(FinishDay command) {
new CanOnlyFinishCurrentDay(command, currentMonth, currentWeek, currentDay).verify();
apply(
DayFinished.event(
command.calendarId(),
command.month(),
command.week(),
command.day()
)
);
}
Calendar() {
// required by Axon
}
}