Search in sources :

Example 1 with Orders

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);
}
Also used : Orders(com.kloia.sample.model.Orders) EventStoreException(com.kloia.eventapis.exception.EventStoreException) ReserveStockEvent(com.kloia.sample.dto.event.ReserveStockEvent)

Example 2 with Orders

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);
}
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)

Example 3 with Orders

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);
}
Also used : Orders(com.kloia.sample.model.Orders) EventStoreException(com.kloia.eventapis.exception.EventStoreException) OrderCancelledEvent(com.kloia.sample.dto.event.OrderCancelledEvent) ReturnPaymentCommandDto(com.kloia.sample.dto.command.ReturnPaymentCommandDto) EventKey(com.kloia.eventapis.common.EventKey) KafkaListener(org.springframework.kafka.annotation.KafkaListener)

Example 4 with Orders

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);
}
Also used : Orders(com.kloia.sample.model.Orders) EventStoreException(com.kloia.eventapis.exception.EventStoreException) PaymentProcessEvent(com.kloia.sample.dto.event.PaymentProcessEvent) PaymentInformation(com.kloia.sample.model.PaymentInformation) KafkaListener(org.springframework.kafka.annotation.KafkaListener)

Aggregations

EventStoreException (com.kloia.eventapis.exception.EventStoreException)4 Orders (com.kloia.sample.model.Orders)4 ReserveStockEvent (com.kloia.sample.dto.event.ReserveStockEvent)2 KafkaListener (org.springframework.kafka.annotation.KafkaListener)2 Command (com.kloia.eventapis.api.Command)1 EventKey (com.kloia.eventapis.common.EventKey)1 ReturnPaymentCommandDto (com.kloia.sample.dto.command.ReturnPaymentCommandDto)1 OrderCancelledEvent (com.kloia.sample.dto.event.OrderCancelledEvent)1 PaymentProcessEvent (com.kloia.sample.dto.event.PaymentProcessEvent)1 PaymentInformation (com.kloia.sample.model.PaymentInformation)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1