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
This commit is contained in:
Steven van Beelen 2018-12-27 09:55:49 +01:00
parent bd0a1efe70
commit eab6dfe0dd
2 changed files with 40 additions and 28 deletions

View File

@ -1,28 +0,0 @@
package com.baeldung.axon.gui;
import java.util.UUID;
import org.axonframework.commandhandling.gateway.CommandGateway;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import com.baeldung.axon.coreapi.commands.CreateMessageCommand;
import com.baeldung.axon.coreapi.commands.MarkReadMessageCommand;
@RestController
public class MessagesRestEndpoint {
private final CommandGateway commandGateway;
public MessagesRestEndpoint(CommandGateway commandGateway) {
this.commandGateway = commandGateway;
}
@PostMapping("/hello")
public void publishMessages() {
final String itemId = UUID.randomUUID().toString();
commandGateway.send(new CreateMessageCommand(itemId, "Hello, how is your day? :-)"));
commandGateway.send(new MarkReadMessageCommand(itemId));
}
}

View File

@ -0,0 +1,40 @@
package com.baeldung.axon.gui;
import java.util.UUID;
import org.axonframework.commandhandling.gateway.CommandGateway;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import com.baeldung.axon.coreapi.commands.ConfirmOrderCommand;
import com.baeldung.axon.coreapi.commands.PlaceOrderCommand;
import com.baeldung.axon.coreapi.commands.ShipOrderCommand;
@RestController
public class OrderRestEndpoint {
private static final String DEFAULT_PRODUCT = "Deluxe Chair";
private final CommandGateway commandGateway;
public OrderRestEndpoint(CommandGateway commandGateway) {
this.commandGateway = commandGateway;
}
@PostMapping("/ship-order")
public void shipOrder() {
String orderId = UUID.randomUUID().toString();
commandGateway.send(new PlaceOrderCommand(orderId, DEFAULT_PRODUCT));
commandGateway.send(new ConfirmOrderCommand(orderId));
commandGateway.send(new ShipOrderCommand(orderId));
}
@PostMapping("/ship-unconfirmed-order")
public void shipUnconfirmedOrder() {
String orderId = UUID.randomUUID().toString();
commandGateway.send(new PlaceOrderCommand(orderId, DEFAULT_PRODUCT));
// This throws an exception, as an Order cannot be shipped if it has not been confirmed yet.
commandGateway.send(new ShipOrderCommand(orderId));
}
}