add fix Demo

This commit is contained in:
Вячеслав Иванов 2024-03-27 21:10:10 +04:00
parent eb62c727ef
commit d59106789a
2 changed files with 32 additions and 8 deletions

View File

@ -27,3 +27,7 @@ dependencies {
tasks.named('test') {
useJUnitPlatform()
}
bootRun {
args = ['--populate']
}

View File

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