Search in sources :

Example 1 with StockAddedEvent

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;
}
Also used : StockAddedEvent(com.kloia.sample.dto.event.StockAddedEvent) EventKey(com.kloia.eventapis.common.EventKey) Stock(com.kloia.sample.model.Stock) Command(com.kloia.eventapis.api.Command) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

Command (com.kloia.eventapis.api.Command)1 EventKey (com.kloia.eventapis.common.EventKey)1 StockAddedEvent (com.kloia.sample.dto.event.StockAddedEvent)1 Stock (com.kloia.sample.model.Stock)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1