diff --git a/delivery/src/main/kotlin/me/rasztabiga/thesis/delivery/domain/command/aggregate/OrderDelivery.kt b/delivery/src/main/kotlin/me/rasztabiga/thesis/delivery/domain/command/aggregate/OrderDelivery.kt index e0e46d8f..9abb2666 100644 --- a/delivery/src/main/kotlin/me/rasztabiga/thesis/delivery/domain/command/aggregate/OrderDelivery.kt +++ b/delivery/src/main/kotlin/me/rasztabiga/thesis/delivery/domain/command/aggregate/OrderDelivery.kt @@ -5,6 +5,7 @@ import me.rasztabiga.thesis.delivery.domain.command.command.DeliverDeliveryComma import me.rasztabiga.thesis.delivery.domain.command.command.PickupDeliveryCommand import me.rasztabiga.thesis.delivery.domain.command.command.RejectDeliveryOfferCommand import me.rasztabiga.thesis.delivery.domain.command.port.CalculateDeliveryFeePort +import me.rasztabiga.thesis.delivery.domain.command.port.CourierOnlineVerifierPort import me.rasztabiga.thesis.delivery.domain.command.port.OrderPreparedVerifierPort import me.rasztabiga.thesis.shared.domain.command.command.CreateOrderDeliveryOfferCommand import me.rasztabiga.thesis.shared.domain.command.event.OrderDeliveryAcceptedEvent @@ -52,8 +53,11 @@ class OrderDelivery { } @CommandHandler - fun handle(command: RejectDeliveryOfferCommand) { + fun handle(command: RejectDeliveryOfferCommand, courierOnlineVerifierPort: CourierOnlineVerifierPort) { require(this.status == DeliveryStatus.OFFER) { "Delivery can be rejected only if it's in OFFER status." } + require(courierOnlineVerifierPort.isCourierOnline(this.courierId!!)) { + "Delivery can be rejected only if the courier is online." + } apply( OrderDeliveryRejectedEvent( @@ -64,8 +68,11 @@ class OrderDelivery { } @CommandHandler - fun handle(command: AcceptDeliveryOfferCommand) { + fun handle(command: AcceptDeliveryOfferCommand, courierOnlineVerifierPort: CourierOnlineVerifierPort) { require(this.status == DeliveryStatus.OFFER) { "Delivery can be accepted only if it's in OFFER status." } + require(courierOnlineVerifierPort.isCourierOnline(this.courierId!!)) { + "Delivery can be accepted only if the courier is online." + } apply( OrderDeliveryAcceptedEvent( @@ -77,7 +84,11 @@ class OrderDelivery { } @CommandHandler - fun handle(command: PickupDeliveryCommand, orderPreparedVerifierPort: OrderPreparedVerifierPort) { + fun handle( + command: PickupDeliveryCommand, + orderPreparedVerifierPort: OrderPreparedVerifierPort, + courierOnlineVerifierPort: CourierOnlineVerifierPort + ) { require(this.status == DeliveryStatus.ACCEPTED) { "Delivery can be picked up only if it's in ACCEPTED status." } require(this.courierId == command.courierId) { "Delivery can be picked up only by the courier who accepted it." @@ -85,6 +96,9 @@ class OrderDelivery { require(orderPreparedVerifierPort.isOrderPrepared(this.orderId)) { "Delivery can be picked up only if the order is prepared." } + require(courierOnlineVerifierPort.isCourierOnline(this.courierId!!)) { + "Delivery can be picked up only if the courier is online." + } apply( OrderDeliveryPickedUpEvent( @@ -96,13 +110,16 @@ class OrderDelivery { } @CommandHandler - fun handle(command: DeliverDeliveryCommand) { + fun handle(command: DeliverDeliveryCommand, courierOnlineVerifierPort: CourierOnlineVerifierPort) { require(this.status == DeliveryStatus.PICKED_UP) { "Delivery can be delivered only if it's in PICKED_UP status." } require(this.courierId == command.courierId) { "Delivery can be delivered only by the courier who picked it up." } + require(courierOnlineVerifierPort.isCourierOnline(this.courierId!!)) { + "Delivery can be delivered only if the courier is online." + } apply( OrderDeliveryDeliveredEvent( diff --git a/delivery/src/main/kotlin/me/rasztabiga/thesis/delivery/domain/command/command/PickupDeliveryCommand.kt b/delivery/src/main/kotlin/me/rasztabiga/thesis/delivery/domain/command/command/PickupDeliveryCommand.kt index 8ed772f6..d9c69a4a 100644 --- a/delivery/src/main/kotlin/me/rasztabiga/thesis/delivery/domain/command/command/PickupDeliveryCommand.kt +++ b/delivery/src/main/kotlin/me/rasztabiga/thesis/delivery/domain/command/command/PickupDeliveryCommand.kt @@ -3,7 +3,6 @@ package me.rasztabiga.thesis.delivery.domain.command.command import org.axonframework.modelling.command.TargetAggregateIdentifier import java.util.UUID -// TODO verify that restaurant order is prepared data class PickupDeliveryCommand( @TargetAggregateIdentifier val id: UUID, val courierId: String diff --git a/delivery/src/main/kotlin/me/rasztabiga/thesis/delivery/domain/command/port/CourierOnlineVerifierPort.kt b/delivery/src/main/kotlin/me/rasztabiga/thesis/delivery/domain/command/port/CourierOnlineVerifierPort.kt new file mode 100644 index 00000000..138741e7 --- /dev/null +++ b/delivery/src/main/kotlin/me/rasztabiga/thesis/delivery/domain/command/port/CourierOnlineVerifierPort.kt @@ -0,0 +1,6 @@ +package me.rasztabiga.thesis.delivery.domain.command.port + +interface CourierOnlineVerifierPort { + + fun isCourierOnline(courierId: String): Boolean +} diff --git a/delivery/src/main/kotlin/me/rasztabiga/thesis/delivery/infrastructure/axon/AxonCourierOnlineVerifierAdapter.kt b/delivery/src/main/kotlin/me/rasztabiga/thesis/delivery/infrastructure/axon/AxonCourierOnlineVerifierAdapter.kt new file mode 100644 index 00000000..f5cccd94 --- /dev/null +++ b/delivery/src/main/kotlin/me/rasztabiga/thesis/delivery/infrastructure/axon/AxonCourierOnlineVerifierAdapter.kt @@ -0,0 +1,22 @@ +package me.rasztabiga.thesis.delivery.infrastructure.axon + +import me.rasztabiga.thesis.delivery.domain.command.port.CourierOnlineVerifierPort +import me.rasztabiga.thesis.shared.adapter.`in`.rest.api.CourierResponse +import me.rasztabiga.thesis.shared.domain.query.query.FindCourierByIdQuery +import org.axonframework.messaging.responsetypes.ResponseTypes +import org.axonframework.queryhandling.QueryGateway +import org.springframework.stereotype.Service + +@Service +class AxonCourierOnlineVerifierAdapter( + private val queryGateway: QueryGateway +) : CourierOnlineVerifierPort { + + override fun isCourierOnline(courierId: String): Boolean { + val courier = queryGateway.query( + FindCourierByIdQuery(courierId), + ResponseTypes.instanceOf(CourierResponse::class.java) + ).join() + return courier.availability == CourierResponse.Availability.ONLINE + } +} diff --git a/frontend/app/models/order.server.ts b/frontend/app/models/order.server.ts index bb760e5b..42940679 100644 --- a/frontend/app/models/order.server.ts +++ b/frontend/app/models/order.server.ts @@ -64,10 +64,11 @@ export interface OrderResponse { restaurantId: string; restaurantLocation: Location; deliveryLocation: Location; + deliveryFee: number; userId: string; status: OrderStatus; items: OrderItemResponse[]; - total: number; + itemsTotal: number; paymentId: string; paymentSessionUrl: string; } diff --git a/frontend/app/routes/ordering.orders.$orderId.payment.tsx b/frontend/app/routes/ordering.orders.$orderId.payment.tsx index 2ed3b672..4a53a3c3 100644 --- a/frontend/app/routes/ordering.orders.$orderId.payment.tsx +++ b/frontend/app/routes/ordering.orders.$orderId.payment.tsx @@ -88,25 +88,21 @@ export default function OrderPaymentPage() { ); })} +
+ {" "} + 1x Delivery fee, {data.order.deliveryFee} PLN +
+Total: {data.order.total} PLN
-Choose payment method
- +Total: {data.order.itemsTotal + data.order.deliveryFee} PLN
Selected delivery address
- TODO +Selected delivery address
+ {data.order.deliveryLocation.streetAddress}Total: {orderSum} PLN
++ delivery fee