Skip to content

Commit eab6dfe

Browse files
committed
BAEL-2435 Switch domain around
Change the domain from 'Messages' to 'Order' as that domain is better suited for an example project like this. Update the endpoint to reflect the order focus i.o. the message focus. Additionally, add a POST endpoint which would return an exception due to the state check in the aggregate
1 parent bd0a1ef commit eab6dfe

2 files changed

Lines changed: 40 additions & 28 deletions

File tree

axon/src/main/java/com/baeldung/axon/gui/MessagesRestEndpoint.java

Lines changed: 0 additions & 28 deletions
This file was deleted.
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package com.baeldung.axon.gui;
2+
3+
import java.util.UUID;
4+
5+
import org.axonframework.commandhandling.gateway.CommandGateway;
6+
import org.springframework.web.bind.annotation.PostMapping;
7+
import org.springframework.web.bind.annotation.RestController;
8+
9+
import com.baeldung.axon.coreapi.commands.ConfirmOrderCommand;
10+
import com.baeldung.axon.coreapi.commands.PlaceOrderCommand;
11+
import com.baeldung.axon.coreapi.commands.ShipOrderCommand;
12+
13+
@RestController
14+
public class OrderRestEndpoint {
15+
16+
private static final String DEFAULT_PRODUCT = "Deluxe Chair";
17+
18+
private final CommandGateway commandGateway;
19+
20+
public OrderRestEndpoint(CommandGateway commandGateway) {
21+
this.commandGateway = commandGateway;
22+
}
23+
24+
@PostMapping("/ship-order")
25+
public void shipOrder() {
26+
String orderId = UUID.randomUUID().toString();
27+
commandGateway.send(new PlaceOrderCommand(orderId, DEFAULT_PRODUCT));
28+
commandGateway.send(new ConfirmOrderCommand(orderId));
29+
commandGateway.send(new ShipOrderCommand(orderId));
30+
}
31+
32+
@PostMapping("/ship-unconfirmed-order")
33+
public void shipUnconfirmedOrder() {
34+
String orderId = UUID.randomUUID().toString();
35+
commandGateway.send(new PlaceOrderCommand(orderId, DEFAULT_PRODUCT));
36+
// This throws an exception, as an Order cannot be shipped if it has not been confirmed yet.
37+
commandGateway.send(new ShipOrderCommand(orderId));
38+
}
39+
40+
}

0 commit comments

Comments
 (0)