-
Notifications
You must be signed in to change notification settings - Fork 12
/
CrudToEventSourcing.xml
137 lines (137 loc) · 9.21 KB
/
CrudToEventSourcing.xml
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<templateSet group="CrudToEventSourcing">
<template name="daop" value="Await.result(publisher.publish(api.ReservationAdded( reservation.listingId, reservation.reservationId, api.Reservation(reservation.checkin, reservation.checkout) )), 5.seconds) " description="" toReformat="false" toShortenFQNames="true">
<context>
<option name="SCALA_CODE" value="true" />
</context>
</template>
<template name="ee" value="sealed trait ReservationEvent extends AggregateEvent[ReservationEvent] { def aggregateTag = ReservationEvent.Tag } object ReservationEvent { val Tag = AggregateEventTag[ReservationEvent] } $END$" description="" toReformat="false" toShortenFQNames="true">
<context>
<option name="SCALA_CODE" value="true" />
</context>
</template>
<template name="eer" value="case class ReservationAdded( listingId: UUID, reservationId: UUID, reservation: Reservation ) extends ReservationEvent object ReservationAdded { implicit val format: Format[ReservationAdded] = Json.format } $END$" description="" toReformat="false" toShortenFQNames="true">
<context>
<option name="SCALA_CODE" value="true" />
</context>
</template>
<template name="ec" value="sealed trait ReservationCommand[R] extends ReplyType[R] $END$" description="" toReformat="false" toShortenFQNames="true">
<context>
<option name="SCALA_CODE" value="true" />
</context>
</template>
<template name="eca" value="case class AddReservation( reservation: Reservation ) extends ReservationCommand[ReservationAdded] object AddReservation { implicit val format: Format[AddReservation] = Json.format } $END$" description="" toReformat="false" toShortenFQNames="true">
<context>
<option name="SCALA_CODE" value="true" />
</context>
</template>
<template name="ecg" value="case object GetCurrentReservations extends ReservationCommand[Seq[Reservation]] { implicit val format: Format[GetCurrentReservations.type] = Format(Reads(_ => JsSuccess(GetCurrentReservations)), Writes(_ => JsString("get"))) } $END$" description="" toReformat="false" toShortenFQNames="true">
<context>
<option name="SCALA_CODE" value="true" />
</context>
</template>
<template name="esr" value="object ReservationSerializerRegistry extends JsonSerializerRegistry { override def serializers: Seq[JsonSerializer[_]] = Seq( JsonSerializer[ReservationAdded], JsonSerializer[AddReservation], JsonSerializer[GetCurrentReservations.type], JsonSerializer[ReservationState] ) } $END$" description="" toReformat="false" toShortenFQNames="true">
<context>
<option name="SCALA_CODE" value="true" />
</context>
</template>
<template name="es" value="case class ReservationState(reservations: Seq[Reservation]) object ReservationState { implicit val format: Format[ReservationState] = Json.format val empty = ReservationState(Nil) } $END$" description="" toReformat="false" toShortenFQNames="true">
<context>
<option name="SCALA_CODE" value="true" />
</context>
</template>
<template name="eb1" value="class ReservationEntity extends PersistentEntity { override type Command = ReservationCommand[_] override type Event = ReservationEvent override type State = ReservationState private lazy val listingId = UUID.fromString(entityId) override def initialState: ReservationState = ReservationState.empty override def behavior: Behavior = { $END$ } }" description="" toReformat="false" toShortenFQNames="true">
<context>
<option name="SCALA_CODE" value="true" />
</context>
</template>
<template name="eb2" value="case ReservationState(reservations) => $END$" description="" toReformat="false" toShortenFQNames="true">
<context>
<option name="SCALA_CODE" value="true" />
</context>
</template>
<template name="eb3" value="Actions().onCommand[AddReservation, ReservationAdded] { case (AddReservation(reservation), ctx, _) => $END$ }" description="" toReformat="false" toShortenFQNames="true">
<context>
<option name="SCALA_CODE" value="true" />
</context>
</template>
<template name="eb4" value="// Validate start/end dates val now = LocalDate.now() if (reservation.checkout.isBefore(reservation.checkin) || reservation.checkout == reservation.checkin) { ctx.commandFailed(BadRequest("Checkout date must be after checkin date")) ctx.done } else if (reservation.checkin.isBefore(now)) { ctx.commandFailed(BadRequest("Cannot make a reservation for the past")) ctx.done // Check that it doesn't overlap with any existing reservations } else if (reservations.exists(_.conflictsWith(reservation))) { ctx.commandFailed(BadRequest("Listing is already booked for those dates")) ctx.done } else { $END$ }" description="" toReformat="false" toShortenFQNames="true">
<context>
<option name="SCALA_CODE" value="true" />
</context>
</template>
<template name="eb5" value="ctx.thenPersist(ReservationAdded(listingId, UUID.randomUUID(), reservation))(ctx.reply)" description="" toReformat="false" toShortenFQNames="true">
<context>
<option name="SCALA_CODE" value="true" />
</context>
</template>
<template name="eb6" value=".onReadOnlyCommand[GetCurrentReservations.type, Seq[Reservation]] { case (GetCurrentReservations, ctx, _) => $END$ }" description="" toReformat="false" toShortenFQNames="true">
<context>
<option name="SCALA_CODE" value="true" />
</context>
</template>
<template name="eb7" value="val now = LocalDate.now() ctx.reply(reservations.dropWhile(_.checkout.isBefore(now)))" description="" toReformat="false" toShortenFQNames="true">
<context>
<option name="SCALA_CODE" value="true" />
</context>
</template>
<template name="eb8" value=".onEvent { case (ReservationAdded(_, _, reservation), state) => $END$ } " description="" toReformat="false" toShortenFQNames="true">
<context>
<option name="SCALA_CODE" value="true" />
</context>
</template>
<template name="eb9" value="ReservationState((reservations :+ reservation) .sortBy(_.checkin.asInstanceOf[ChronoLocalDate]))" description="" toReformat="false" toShortenFQNames="true">
<context>
<option name="SCALA_CODE" value="true" />
</context>
</template>
<template name="re" value="persistentEntityRegistry.register(wire[ReservationEntity])" description="" toReformat="false" toShortenFQNames="true">
<context>
<option name="SCALA_CODE" value="true" />
</context>
</template>
<template name="ref" value="private def reservationEntity(listingId: UUID): PersistentEntityRef[ReservationCommand[_]] = { persistentEntityRegistry.refFor[ReservationEntity](listingId.toString) } " description="" toReformat="false" toShortenFQNames="true">
<context>
<option name="SCALA_CODE" value="true" />
</context>
</template>
<template name="sr1" value="reservationEntity(listingId) $END$" description="" toReformat="false" toShortenFQNames="true">
<context>
<option name="SCALA_CODE" value="true" />
</context>
</template>
<template name="sr2" value=".ask(AddReservation(reservation)) " description="" toReformat="false" toShortenFQNames="true">
<context>
<option name="SCALA_CODE" value="true" />
</context>
</template>
<template name="sr3" value=".map { added => api.ReservationAdded(added.listingId, added.reservationId, added.reservation) }" description="" toReformat="false" toShortenFQNames="true">
<context>
<option name="SCALA_CODE" value="true" />
</context>
</template>
<template name="sg" value="reservationEntity(listingId).ask(GetCurrentReservations)" description="" toReformat="false" toShortenFQNames="true">
<context>
<option name="SCALA_CODE" value="true" />
</context>
</template>
<template name="se1" value="TopicProducer.taggedStreamWithOffset(immutable.Seq(ReservationEvent.Tag)) { (tag, offset) => $END$ }" description="" toReformat="false" toShortenFQNames="true">
<context>
<option name="SCALA_CODE" value="true" />
</context>
</template>
<template name="se2" value="persistentEntityRegistry.eventStream(tag, offset)" description="" toReformat="false" toShortenFQNames="true">
<context>
<option name="SCALA_CODE" value="true" />
</context>
</template>
<template name="se3" value=".map { case EventStreamElement(_, ReservationAdded(listingId, reservationId, reservation), offset) => $END$ } " description="" toReformat="false" toShortenFQNames="true">
<context>
<option name="SCALA_CODE" value="true" />
</context>
</template>
<template name="se4" value="api.ReservationAdded(listingId, reservationId, reservation) -> offset" description="" toReformat="false" toShortenFQNames="true">
<context>
<option name="SCALA_CODE" value="true" />
</context>
</template>
</templateSet>