Search in sources :

Example 1 with ReserveStockEvent

use of com.kloia.sample.dto.event.ReserveStockEvent in project eventapis by kloiasoft.

the class ProcessOrderCommand method execute.

@Override
public EventKey execute(@RequestBody ProcessOrderCommandDto dto) throws Exception {
    Orders order = orderQuery.queryEntity(dto.getOrderId());
    if (order.getState() == OrderState.INITIAL) {
        ReserveStockEvent reserveStockEvent = new ReserveStockEvent(order.getStockId(), order.getOrderAmount(), dto.getPaymentInformation());
        log.info("Template account saved: " + dto);
        return eventRepository.recordAndPublish(order, reserveStockEvent);
    } else
        throw new EventStoreException("Order state is not valid for this Operation: " + dto);
}
Also used : Orders(com.kloia.sample.model.Orders) EventStoreException(com.kloia.eventapis.exception.EventStoreException) ReserveStockEvent(com.kloia.sample.dto.event.ReserveStockEvent)

Example 2 with ReserveStockEvent

use of com.kloia.sample.dto.event.ReserveStockEvent in project eventapis by kloiasoft.

the class ProcessOrderCommand method process.

@RequestMapping(value = "/order/{orderId}/process", method = RequestMethod.POST)
@Command
public EventKey process(@PathVariable("orderId") String orderId, @RequestBody @Valid ProcessOrderCommandDto dto) throws Exception {
    dto.setOrderId(orderId);
    Orders order = orderQuery.queryEntity(dto.getOrderId());
    if (order.getState() == OrderState.INITIAL) {
        ReserveStockEvent reserveStockEvent = new ReserveStockEvent(order.getStockId(), order.getOrderAmount(), dto.getPaymentInformation());
        log.info("Template account saved: " + dto);
        return eventRepository.recordAndPublish(order, reserveStockEvent);
    } else
        throw new EventStoreException("Order state is not valid for this Operation: " + dto);
}
Also used : Orders(com.kloia.sample.model.Orders) EventStoreException(com.kloia.eventapis.exception.EventStoreException) ReserveStockEvent(com.kloia.sample.dto.event.ReserveStockEvent) Command(com.kloia.eventapis.api.Command) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

EventStoreException (com.kloia.eventapis.exception.EventStoreException)2 ReserveStockEvent (com.kloia.sample.dto.event.ReserveStockEvent)2 Orders (com.kloia.sample.model.Orders)2 Command (com.kloia.eventapis.api.Command)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1