|
| 1 | +/* |
| 2 | + * This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt). |
| 3 | + * |
| 4 | + * The MIT License |
| 5 | + * Copyright © 2014-2022 Ilkka Seppälä |
| 6 | + * |
| 7 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 8 | + * of this software and associated documentation files (the "Software"), to deal |
| 9 | + * in the Software without restriction, including without limitation the rights |
| 10 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 11 | + * copies of the Software, and to permit persons to whom the Software is |
| 12 | + * furnished to do so, subject to the following conditions: |
| 13 | + * |
| 14 | + * The above copyright notice and this permission notice shall be included in |
| 15 | + * all copies or substantial portions of the Software. |
| 16 | + * |
| 17 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 18 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 19 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 20 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 21 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 22 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 23 | + * THE SOFTWARE. |
| 24 | + */ |
| 25 | +package com.iluwatar.verticalslicearchitecture; |
| 26 | + |
| 27 | +import com.iluwatar.verticalslicearchitecture.customer.Customer; |
| 28 | +import com.iluwatar.verticalslicearchitecture.customer.CustomerService; |
| 29 | +import com.iluwatar.verticalslicearchitecture.customer.CustomerView; |
| 30 | +import com.iluwatar.verticalslicearchitecture.order.OrderService; |
| 31 | +import com.iluwatar.verticalslicearchitecture.order.OrderView; |
| 32 | +import com.iluwatar.verticalslicearchitecture.product.Product; |
| 33 | +import com.iluwatar.verticalslicearchitecture.product.ProductService; |
| 34 | +import com.iluwatar.verticalslicearchitecture.product.ProductView; |
| 35 | +import lombok.AllArgsConstructor; |
| 36 | +import lombok.extern.slf4j.Slf4j; |
| 37 | +import org.springframework.boot.CommandLineRunner; |
| 38 | +import org.springframework.stereotype.Component; |
| 39 | + |
| 40 | +/** |
| 41 | + * Seeding test data. |
| 42 | + */ |
| 43 | + |
| 44 | +@Component |
| 45 | +@AllArgsConstructor |
| 46 | +@Slf4j |
| 47 | +public class Runner implements CommandLineRunner { |
| 48 | + |
| 49 | + CustomerService customerService; |
| 50 | + OrderService orderService; |
| 51 | + ProductService productService; |
| 52 | + |
| 53 | + @Override |
| 54 | + public void run(String... args) { |
| 55 | + initializeData(); |
| 56 | + new OrderView(orderService).render(customerService.getCustomerById(1)); |
| 57 | + new CustomerView(customerService).render(); |
| 58 | + new ProductView(productService).render(); |
| 59 | + } |
| 60 | + |
| 61 | + /** |
| 62 | + * method for data seeds. |
| 63 | + */ |
| 64 | + |
| 65 | + public void initializeData() { |
| 66 | + |
| 67 | + Customer customer = Customer. builder(). id( 1). name( "sugan0tech"). email( "[email protected]"). build(); |
| 68 | + customerService.createCustomer(customer); |
| 69 | + |
| 70 | + Product oreo = Product.builder().id(1).price(2.00).name("Oreo").build(); |
| 71 | + Product cone = Product.builder().id(3).price(1.15).name("Ice Cream Cone").build(); |
| 72 | + Product apple = Product.builder().id(4).price(2.00).name("Apple").build(); |
| 73 | + Product sandwich = Product.builder().id(2).price(6.00).name("Sandwich").build(); |
| 74 | + productService.createProduct(oreo); |
| 75 | + productService.createProduct(cone); |
| 76 | + productService.createProduct(apple); |
| 77 | + productService.createProduct(sandwich); |
| 78 | + |
| 79 | + orderService.createOrder(1, customer, oreo); |
| 80 | + orderService.createOrder(2, customer, sandwich); |
| 81 | + orderService.createOrder(3, customer, apple); |
| 82 | + } |
| 83 | +} |
0 commit comments