Search in sources :

Example 1 with AddStockCommandDto

use of com.kloia.sample.dto.command.AddStockCommandDto in project eventapis by kloiasoft.

the class CreateStockCommandHandler method execute.

@RequestMapping(value = "/stock/create", method = RequestMethod.POST)
@Command
public EventKey execute(@RequestBody CreateStockCommandDto dto) throws Exception {
    StockCreatedEvent stockCreatedEvent = new StockCreatedEvent();
    BeanUtils.copyProperties(dto, stockCreatedEvent);
    EventKey eventKey = eventRepository.recordAndPublish(stockCreatedEvent);
    try {
        addStockCommandHandler.execute(eventKey.getEntityId(), new AddStockCommandDto(dto.getRemainingStock(), eventKey.getEntityId()));
    } catch (Exception e) {
        log.warn("Sub Command Failed:" + e.getMessage());
    }
    return eventKey;
}
Also used : StockCreatedEvent(com.kloia.sample.dto.event.StockCreatedEvent) AddStockCommandDto(com.kloia.sample.dto.command.AddStockCommandDto) EventKey(com.kloia.eventapis.common.EventKey) 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 AddStockCommandDto (com.kloia.sample.dto.command.AddStockCommandDto)1 StockCreatedEvent (com.kloia.sample.dto.event.StockCreatedEvent)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1