use of com.kloia.sample.model.Orders 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);
}
use of com.kloia.sample.model.Orders 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);
}
use of com.kloia.sample.model.Orders in project eventapis by kloiasoft.
the class StockReleasedEventHandler method execute.
@KafkaListener(topics = "StockReleasedEvent", containerFactory = "eventsKafkaListenerContainerFactory")
public EventKey execute(StockReleasedEvent dto) throws EventStoreException, ConcurrentEventException {
Orders order = orderQuery.queryEntity(dto.getOrderId());
if (order.getState() == OrderState.RELEASING_STOCK) {
OrderCancelledEvent orderCancelledEvent = new OrderCancelledEvent();
log.info("Payment is processing : " + dto);
EventKey eventKey = eventRepository.recordAndPublish(order, orderCancelledEvent);
paymentClient.returnPaymentCommand(order.getPaymentId(), new ReturnPaymentCommandDto(order.getId()));
return eventKey;
} else
throw new EventStoreException("Order state is not valid for this Operation: " + dto);
}
use of com.kloia.sample.model.Orders in project eventapis by kloiasoft.
the class StockReservedEventHandler method execute.
@Override
@KafkaListener(topics = "StockReservedEvent", containerFactory = "eventsKafkaListenerContainerFactory")
public EventKey execute(StockReservedEvent dto) throws EventStoreException, ConcurrentEventException {
Orders order = orderQuery.queryEntity(dto.getOrderId());
if (order.getState() == OrderState.RESERVING_STOCK) {
PaymentProcessEvent paymentProcessEvent = new PaymentProcessEvent(order.getId(), dto.getSender().getVersion(), new PaymentInformation(order.getPaymentAddress(), order.getAmount(), order.getCardInformation()));
log.info("Payment is processing : " + dto);
return eventRepository.recordAndPublish(order, paymentProcessEvent);
} else
throw new EventStoreException("Order state is not valid for this Operation: " + dto);
}
Aggregations