// {!begin cancelOrder}
@RequestMapping(method = RequestMethod.DELETE, value = "/{id}")
public ResponseEntity<Order> cancelOrder(@PathVariable String id) {
OrderDeletedEvent orderDeleted = orderService.deleteOrder(new DeleteOrderEvent(UUID.fromString(id)));
if (!orderDeleted.isEntityFound()) {
return new ResponseEntity<Order>(HttpStatus.NOT_FOUND);
}
Order order = Order.fromOrderDetails(orderDeleted.getDetails());
if (orderDeleted.isDeletionCompleted()) {
return new ResponseEntity<Order>(order, HttpStatus.OK);
}
return new ResponseEntity<Order>(order, HttpStatus.FORBIDDEN);
}