use of com.kloia.sample.dto.event.StockAddedEvent in project eventapis by kloiasoft.
the class AddStockCommandHandler method execute.
@RequestMapping(value = "/stock/{stockId}/add", method = RequestMethod.POST)
@Command()
public EventKey execute(String stockId, @RequestBody AddStockCommandDto dto) throws Exception {
dto.setStockId(stockId);
Stock stock = stockQuery.queryEntity(dto.getStockId());
if (dto.getStockToAdd() > 1000000)
throw new IllegalArgumentException("Invalid Stock to Add");
EventKey eventKey = eventRepository.recordAndPublish(stock.getEventKey(), new StockAddedEvent(dto.getStockToAdd()));
return eventKey;
}
Aggregations