use of com.kloia.eventapis.api.Command 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;
}
use of com.kloia.eventapis.api.Command in project eventapis by kloiasoft.
the class ReturnPaymentCommand method execute.
@RequestMapping(value = "/payment/{paymentId}/return", method = RequestMethod.POST)
@Command
public EventKey execute(@PathVariable("paymentId") String paymentId, @RequestBody @Valid ReturnPaymentCommandDto dto) throws Exception {
dto.setPaymentId(paymentId);
Payment payment = paymentViewQuery.queryEntity(dto.getPaymentId());
if (payment.getState() == PaymentState.PAID) {
PaymentReturnedEvent paymentReturnedEvent = new PaymentReturnedEvent(payment.getOrderId(), payment.getAmount());
return eventRepository.recordAndPublish(payment, paymentReturnedEvent);
} else
throw new EventStoreException("Payment state is not valid for this Operation: " + dto);
}
use of com.kloia.eventapis.api.Command in project eventapis by kloiasoft.
the class CreateOrderCommand method execute.
@RequestMapping(value = "/order/create", method = RequestMethod.POST)
@Command
public EventKey execute(@RequestBody @Valid CreateOrderCommandDto dto) throws Exception {
OrderCreatedEvent orderCreatedEvent = new OrderCreatedEvent();
BeanUtils.copyProperties(dto, orderCreatedEvent);
return eventRepository.recordAndPublish(orderCreatedEvent);
}
use of com.kloia.eventapis.api.Command 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.eventapis.api.Command 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;
}
Aggregations