Skip to content

Commit

Permalink
Merge pull request #53 from igor-toporet/typo-payed-to-paid
Browse files Browse the repository at this point in the history
Fix typo (from "payed" to "paid")
  • Loading branch information
idugalic committed Jan 8, 2024
2 parents 5541c14 + 7a47c64 commit 92a84c1
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -266,13 +266,13 @@ internal class EventStore(private val connectionFactory: ConnectionFactory) {
VALUES ('Order', 'com.fraktalio.domain.OrderPreparedEvent');
INSERT INTO deciders
VALUES ('Order', 'com.fraktalio.domain.OrderPayedEvent');
VALUES ('Order', 'com.fraktalio.domain.OrderPaidEvent');
INSERT INTO deciders
VALUES ('Order', 'com.fraktalio.domain.OrderNotPreparedEvent');
INSERT INTO deciders
VALUES ('Order', 'com.fraktalio.domain.OrderNotPayedEvent');
VALUES ('Order', 'com.fraktalio.domain.OrderNotPaidEvent');
INSERT INTO deciders
VALUES ('Order', 'com.fraktalio.domain.OrderRejectedEvent');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.fraktalio.adapter.publisher
import com.fraktalio.LOGGER
import com.fraktalio.application.Aggregate
import com.fraktalio.domain.Command
import com.fraktalio.domain.MarkOrderAsPayedCommand
import com.fraktalio.domain.MarkOrderAsPaidCommand
import com.fraktalio.domain.PayCommand
import com.fraktalio.fmodel.application.ActionPublisher
import com.fraktalio.fmodel.application.handleOptimistically
Expand All @@ -22,7 +22,7 @@ class PaymentActionPublisher(private val aggregate: Aggregate) : ActionPublisher
LOGGER.info("Publishing command to the Payment service: $it")
delay(1000)
// once you get the response from the Payment service, you can emit command back to the internal aggregate
aggregate.handleOptimistically(MarkOrderAsPayedCommand((it as PayCommand).orderId)).collect()
aggregate.handleOptimistically(MarkOrderAsPaidCommand((it as PayCommand).orderId)).collect()
// simply emit the successfully published command(s)
emit(it)
}
Expand Down
8 changes: 4 additions & 4 deletions src/main/kotlin/com/fraktalio/domain/OrderDecider.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ fun orderDecider() = OrderDecider(
)
else flowOf(OrderPreparedEvent(c.identifier))

is MarkOrderAsPayedCommand ->
if (s == null) flowOf(OrderNotPayedEvent(c.identifier, Reason("Order does not exist")))
is MarkOrderAsPaidCommand ->
if (s == null) flowOf(OrderNotPaidEvent(c.identifier, Reason("Order does not exist")))
else if (OrderStatus.PREPARED != s.status) flowOf(
OrderNotPreparedEvent(
c.identifier,
Reason("Order not in PREPARED status"),
)
)
else flowOf(OrderPayedEvent(c.identifier))
else flowOf(OrderPaidEvent(c.identifier))


null -> emptyFlow() // We ignore the `null` command by emitting the empty flow. Only the Decider that can handle `null` command can be combined (Monoid) with other Deciders.
Expand All @@ -56,7 +56,7 @@ fun orderDecider() = OrderDecider(
when (e) {
is OrderCreatedEvent -> Order(e.identifier, e.restaurantId, e.status, e.lineItems)
is OrderPreparedEvent -> s?.copy(status = e.status)
is OrderPayedEvent -> s?.copy(status = e.status)
is OrderPaidEvent -> s?.copy(status = e.status)
is OrderRejectedEvent -> s?.copy(status = e.status)
is OrderErrorEvent -> s // Error events are not changing the state in our/this case.
null -> s // Null events are not changing the state / We return current state instead. Only the Decider that can handle `null` event can be combined (Monoid) with other Deciders.
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/com/fraktalio/domain/OrderView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ fun orderView() = OrderView(
when (e) {
is OrderCreatedEvent -> OrderViewState(e.identifier, e.restaurantId, e.status, e.lineItems)
is OrderPreparedEvent -> s?.copy(status = e.status)
is OrderPayedEvent -> s?.copy(status = e.status)
is OrderPaidEvent -> s?.copy(status = e.status)
is OrderRejectedEvent -> s?.copy(status = e.status)
is OrderErrorEvent -> s // Error events are not changing the state in our/this case.
null -> s // Null events are not changing the state / We return current state instead. Only the Decider that can handle `null` event can be combined (Monoid) with other Deciders.
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/com/fraktalio/domain/PaymentSaga.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ fun paymentSaga() = PaymentSaga(
is OrderPreparedEvent -> flowOf(PayCommand(orderId = e.identifier))
is OrderCreatedEvent -> emptyFlow()
is OrderErrorEvent -> emptyFlow()
is OrderPayedEvent -> emptyFlow()
is OrderPaidEvent -> emptyFlow()
is RestaurantEvent -> emptyFlow()
null -> emptyFlow() // We ignore the `null` event by returning the empty flow of commands. Only the Saga that can handle `null` event/action-result can be combined (Monoid) with other Sagas.
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/com/fraktalio/domain/RestaurantSaga.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ fun restaurantSaga() = RestaurantSaga(
//TODO evolve the example ;), it does not do much at the moment.
is OrderCreatedEvent -> emptyFlow()
is OrderPreparedEvent -> emptyFlow()
is OrderPayedEvent -> emptyFlow()
is OrderPaidEvent -> emptyFlow()
is OrderErrorEvent -> emptyFlow()
null -> emptyFlow() // We ignore the `null` event by returning the empty flow of commands. Only the Saga that can handle `null` event/action-result can be combined (Monoid) with other Sagas.
}
Expand Down
10 changes: 5 additions & 5 deletions src/main/kotlin/com/fraktalio/domain/api.kt
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ data class OrderLineItem(

@Serializable
enum class OrderStatus {
CREATED, PREPARED, REJECTED, CANCELLED, PAYED
CREATED, PREPARED, REJECTED, CANCELLED, PAID
}

@Serializable
Expand Down Expand Up @@ -178,7 +178,7 @@ data class MarkOrderAsPreparedCommand(
) : OrderCommand()

@Serializable
data class MarkOrderAsPayedCommand(
data class MarkOrderAsPaidCommand(
override val identifier: OrderId,
) : OrderCommand()

Expand Down Expand Up @@ -299,11 +299,11 @@ data class OrderPreparedEvent(
}

@Serializable
data class OrderPayedEvent(
data class OrderPaidEvent(
override val identifier: OrderId,
override val final: Boolean = false,
) : OrderEvent() {
val status: OrderStatus = OrderStatus.PAYED
val status: OrderStatus = OrderStatus.PAID
}

@Serializable
Expand All @@ -314,7 +314,7 @@ data class OrderNotPreparedEvent(
) : OrderErrorEvent()

@Serializable
data class OrderNotPayedEvent(
data class OrderNotPaidEvent(
override val identifier: OrderId,
override val reason: Reason,
override val final: Boolean = false,
Expand Down

0 comments on commit 92a84c1

Please sign in to comment.