BAEL-3777: Included CLI mode
This commit is contained in:
parent
92640684d8
commit
a8617b62fa
|
@ -1,13 +1,49 @@
|
|||
package com.baeldung.dddhexagonalspring;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.annotation.PropertySource;
|
||||
|
||||
import com.baeldung.dddhexagonalspring.application.cli.CliOrderController;
|
||||
import com.baeldung.dddhexagonalspring.domain.Product;
|
||||
|
||||
@SpringBootApplication
|
||||
@PropertySource(value = { "classpath:ddd-layers.properties" })
|
||||
public class DomainLayerApplication {
|
||||
public class DomainLayerApplication implements CommandLineRunner {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(DomainLayerApplication.class);
|
||||
|
||||
public static void main(final String[] args) {
|
||||
SpringApplication.run(DomainLayerApplication.class, args);
|
||||
SpringApplication application = new SpringApplication(DomainLayerApplication.class);
|
||||
// uncomment to run just the console application
|
||||
// application.setWebApplicationType(WebApplicationType.NONE);
|
||||
application.run(args);
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public CliOrderController orderController;
|
||||
|
||||
@Autowired
|
||||
public ConfigurableApplicationContext context;
|
||||
|
||||
@Override
|
||||
public void run(String... args) throws Exception {
|
||||
LOG.info("Placing a new CLI order with two products");
|
||||
Product mobilePhone = new Product(UUID.randomUUID(), BigDecimal.valueOf(200), "mobile");
|
||||
Product razor = new Product(UUID.randomUUID(), BigDecimal.valueOf(50), "razor");
|
||||
LOG.info("Creating order with mobile phone");
|
||||
UUID orderId = orderController.createOrder(mobilePhone);
|
||||
LOG.info("Adding a razor to the order");
|
||||
orderController.addProduct(orderId, razor);
|
||||
LOG.info("Completing order");
|
||||
orderController.completeOrder(orderId);
|
||||
LOG.info("Order placement complete");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
package com.baeldung.dddhexagonalspring.application.cli;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.baeldung.dddhexagonalspring.domain.Product;
|
||||
import com.baeldung.dddhexagonalspring.domain.service.OrderService;
|
||||
|
||||
@Component
|
||||
public class CliOrderController{
|
||||
|
||||
private final OrderService orderService;
|
||||
|
||||
@Autowired
|
||||
public CliOrderController(OrderService orderService) {
|
||||
this.orderService = orderService;
|
||||
}
|
||||
|
||||
public UUID createOrder(Product product) {
|
||||
return orderService.createOrder(product);
|
||||
}
|
||||
|
||||
public void addProduct(UUID orderId, Product product) {
|
||||
orderService.addProduct(orderId, product);
|
||||
}
|
||||
|
||||
public void deleteProduct(UUID orderId, UUID productId) {
|
||||
orderService.deleteProduct(orderId, productId);
|
||||
|
||||
}
|
||||
|
||||
public void completeOrder(UUID orderId) {
|
||||
orderService.completeOrder(orderId);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package com.baeldung.dddhexagonalspring.application.controller;
|
||||
package com.baeldung.dddhexagonalspring.application.rest;
|
||||
|
||||
import com.baeldung.dddhexagonalspring.application.request.AddProductRequest;
|
||||
import com.baeldung.dddhexagonalspring.application.request.CreateOrderRequest;
|
||||
|
@ -12,12 +12,12 @@ import java.util.UUID;
|
|||
|
||||
@RestController
|
||||
@RequestMapping("/orders")
|
||||
public class OrderController {
|
||||
public class RestOrderController {
|
||||
|
||||
private final OrderService orderService;
|
||||
|
||||
@Autowired
|
||||
public OrderController(OrderService orderService) {
|
||||
public RestOrderController(OrderService orderService) {
|
||||
this.orderService = orderService;
|
||||
}
|
||||
|
|
@ -11,7 +11,6 @@ import com.baeldung.dddhexagonalspring.domain.Order;
|
|||
import com.baeldung.dddhexagonalspring.domain.repository.OrderRepository;
|
||||
|
||||
@Component
|
||||
@Primary
|
||||
public class CassandraDbOrderRepository implements OrderRepository {
|
||||
|
||||
private final SpringDataCassandraOrderRepository orderRepository;
|
||||
|
|
|
@ -4,12 +4,14 @@ import java.util.Optional;
|
|||
import java.util.UUID;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.baeldung.dddhexagonalspring.domain.Order;
|
||||
import com.baeldung.dddhexagonalspring.domain.repository.OrderRepository;
|
||||
|
||||
@Component
|
||||
@Primary
|
||||
public class MongoDbOrderRepository implements OrderRepository {
|
||||
|
||||
private final SpringDataMongoOrderRepository orderRepository;
|
||||
|
|
Loading…
Reference in New Issue