From d59106789a09579a57bc2e86000f9cbe326db926 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D1=8F=D1=87=D0=B5=D1=81=D0=BB=D0=B0=D0=B2=20=D0=98?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD=D0=BE=D0=B2?= Date: Wed, 27 Mar 2024 21:10:10 +0400 Subject: [PATCH] add fix Demo --- demo/build.gradle | 4 +++ .../com/example/demo/DemoApplication.java | 36 ++++++++++++++----- 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/demo/build.gradle b/demo/build.gradle index 14c3827..308d2ae 100644 --- a/demo/build.gradle +++ b/demo/build.gradle @@ -27,3 +27,7 @@ dependencies { tasks.named('test') { useJUnitPlatform() } + +bootRun { + args = ['--populate'] +} diff --git a/demo/src/main/java/com/example/demo/DemoApplication.java b/demo/src/main/java/com/example/demo/DemoApplication.java index 73c5fba..d15a5a4 100644 --- a/demo/src/main/java/com/example/demo/DemoApplication.java +++ b/demo/src/main/java/com/example/demo/DemoApplication.java @@ -8,10 +8,14 @@ import org.springframework.boot.CommandLineRunner; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import com.example.demo.orders.model.OrderEntity; +import com.example.demo.orders.service.OrderService; import com.example.demo.product.model.ProductEntity; import com.example.demo.product.service.ProductService; import com.example.demo.types.model.TypeEntity; import com.example.demo.types.service.TypeService; +import com.example.demo.users.model.UserEntity; +import com.example.demo.users.service.UserService; @SpringBootApplication public class DemoApplication implements CommandLineRunner { @@ -19,10 +23,14 @@ public class DemoApplication implements CommandLineRunner { private final TypeService typeService; private final ProductService productService; + private final OrderService orderService; + private final UserService userService; - public DemoApplication(TypeService typeService, ProductService productService) { + public DemoApplication(TypeService typeService, ProductService productService, OrderService orderService, UserService userService) { this.typeService = typeService; this.productService = productService; + this.orderService = orderService; + this.userService = userService; } public static void main(String[] args) { @@ -38,13 +46,25 @@ public class DemoApplication implements CommandLineRunner { final var type3 = typeService.create(new TypeEntity(null, "Сырная")); log.info("Create default product values"); - productService.create(new ProductEntity(null, "test", type1, 399.00)); - productService.create(new ProductEntity(null, "test", type1, 499.00)); - productService.create(new ProductEntity(null, "test", type2, 450.50)); - productService.create(new ProductEntity(null, "test", type2, 900.50)); - productService.create(new ProductEntity(null, "test", type2, 600.00)); - productService.create(new ProductEntity(null, "test", type3, 750.00)); - productService.create(new ProductEntity(null, "test", type3, 670.00)); + final var product1 = productService.create(new ProductEntity(null, "test", type1, 399.00)); + final var product2 = productService.create(new ProductEntity(null, "test", type1, 499.00)); + final var product3 = productService.create(new ProductEntity(null, "test", type2, 450.50)); + final var product4 = productService.create(new ProductEntity(null, "test", type2, 900.50)); + final var product5 = productService.create(new ProductEntity(null, "test", type2, 600.00)); + final var product6 = productService.create(new ProductEntity(null, "test", type3, 750.00)); + + log.info("Create default user values"); + final var user1 = userService.create(new UserEntity(null, "test", "test", "test")); + final var user2 = userService.create(new UserEntity(null, "test1", "test1", "test1")); + final var user3 = userService.create(new UserEntity(null, "test2", "test2", "test2")); + + log.info("Create default order values"); + orderService.create(new OrderEntity(null, user1, product1, 10)); + orderService.create(new OrderEntity(null, user2, product2, 5)); + orderService.create(new OrderEntity(null, user3, product3, 15)); + orderService.create(new OrderEntity(null, user1, product4, 6)); + orderService.create(new OrderEntity(null, user2, product5, 8)); + orderService.create(new OrderEntity(null, user3, product6, 3)); } } }