Commit 51f4fe21 authored by Shanelle Valencia's avatar Shanelle Valencia

[AFP-53] Persist order info from warehouse to db [@svalencia]

parents 956663f8 227a8068
Pipeline #1700 failed with stage
in 39 seconds
......@@ -3,5 +3,5 @@ package com.afp.ordermanagement.model;
public enum OrderStatus {
RECEIVED,
FULFILLED,
CANCELLED
CANCELLED,
}
......@@ -31,10 +31,6 @@ public class Receiver {
@Autowired
private OrderService orderService;
@Autowired
private OrderRepository orderRepository;
@EventListener(ApplicationStartedEvent.class)
public void consumeOrderStatus() {
......@@ -48,18 +44,20 @@ public class Receiver {
private void updateOrderStatus(String orderStatusStr) {
private void updateOrderStatus(String orderObj) {
try {
//deserialize kafka message into java object using ObjectMapper
ObjectMapper objectMapper = new ObjectMapper();
//Map<String, String> orderStatus = objectMapper.readValue(orderStatusStr, Map.class);
Order order = objectMapper.readValue(orderStatusStr, Order.class);
Order order = objectMapper.readValue(orderObj, Order.class);
log.info("ORDER objectMapper {}", order);
String orderId = order.getId();
Mono<Order> updated = orderService.updateOrderByOrderId(orderId, order);
updated.block();
} catch (Exception e) {
log.error("Caught error", e);
}
......@@ -76,13 +74,16 @@ public class Receiver {
.findAny()
.orElse(null);
if (res == null) {
log.error("Order {} not found", orderId);
return false;
}
log.info("Order exists on the database");
return true;
}
......
......@@ -58,5 +58,9 @@ public class OrderService {
}
public Mono<Void> deleteOrderById(String orderId) {
return orderRepository.deleteById(orderId);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment