diff --git a/2 семестр/lab3/demo/build.gradle b/2 семестр/lab3/demo/build.gradle index 42a3cac..a02850f 100644 --- a/2 семестр/lab3/demo/build.gradle +++ b/2 семестр/lab3/demo/build.gradle @@ -41,3 +41,7 @@ dependencies { tasks.named('test') { useJUnitPlatform() } + +bootRun { + args = ['--populate'] +} \ No newline at end of file diff --git a/2 семестр/lab3/demo/src/main/java/com/example/demo/DemoApplication.java b/2 семестр/lab3/demo/src/main/java/com/example/demo/DemoApplication.java index 04bcd9d..219eba7 100644 --- a/2 семестр/lab3/demo/src/main/java/com/example/demo/DemoApplication.java +++ b/2 семестр/lab3/demo/src/main/java/com/example/demo/DemoApplication.java @@ -47,12 +47,12 @@ public class DemoApplication implements CommandLineRunner { final var type3 = typeService.create(new TypeEntity("Сырная")); log.info("Create default product values"); - final var product1 = productService.create(new ProductEntity("test", type1, 399.00, 15)); - final var product2 = productService.create(new ProductEntity("test", type1, 499.00, 10)); - final var product3 = productService.create(new ProductEntity("test", type2, 450.50, 5)); - final var product4 = productService.create(new ProductEntity("test", type2, 900.50, 6)); - final var product5 = productService.create(new ProductEntity("test", type2, 600.00, 8)); - final var product6 = productService.create(new ProductEntity("test", type3, 750.00, 9)); + final var product1 = productService.create(new ProductEntity("test", type1, 399.00)); + final var product2 = productService.create(new ProductEntity("test", type1, 499.00)); + final var product3 = productService.create(new ProductEntity("test", type2, 450.50)); + final var product4 = productService.create(new ProductEntity("test", type2, 900.50)); + final var product5 = productService.create(new ProductEntity("test", type2, 600.00)); + final var product6 = productService.create(new ProductEntity("test", type3, 750.00)); log.info("Create default user values"); final var user1 = userService.create(new UserEntity("kruviii", "Павел", "Крылов", "test@test.ru", "11-11-2023", "+79876543210", "qwerty123")); diff --git a/2 семестр/lab3/demo/src/main/java/com/example/demo/orders/service/OrderService.java b/2 семестр/lab3/demo/src/main/java/com/example/demo/orders/service/OrderService.java index 1294996..7722aeb 100644 --- a/2 семестр/lab3/demo/src/main/java/com/example/demo/orders/service/OrderService.java +++ b/2 семестр/lab3/demo/src/main/java/com/example/demo/orders/service/OrderService.java @@ -81,7 +81,7 @@ public class OrderService { public List getOrderProducts(long userId, long id) { userService.get(userId); return get(userId, id).getOrderProducts().stream() - .map(OrderProductEntity::getProduct) + .map(orderProduct -> orderProduct.getProduct()) .toList(); } @@ -114,7 +114,7 @@ public class OrderService { result.forEach(product -> { final OrderProductEntity orderProduct = new OrderProductEntity(existsOrder, product, productsIdsCount.get(product.getId())); orderProduct.setOrder(existsOrder); - orderProduct.setProduct(product); + // orderProduct.setProduct(product); }); repository.save(existsOrder); return result; diff --git a/2 семестр/lab3/demo/src/main/java/com/example/demo/ordersproducts/model/OrderProductEntity.java b/2 семестр/lab3/demo/src/main/java/com/example/demo/ordersproducts/model/OrderProductEntity.java index 2b83fc9..2cd15ec 100644 --- a/2 семестр/lab3/demo/src/main/java/com/example/demo/ordersproducts/model/OrderProductEntity.java +++ b/2 семестр/lab3/demo/src/main/java/com/example/demo/ordersproducts/model/OrderProductEntity.java @@ -61,13 +61,6 @@ public class OrderProductEntity { return product; } - public void setProduct(ProductEntity product) { - this.product = product; - if (!product.getOrderProducts().contains(this)) { - product.getOrderProducts().add(this); - } - } - public Integer getCount() { return count; } diff --git a/2 семестр/lab3/demo/src/main/java/com/example/demo/product/api/ProductDto.java b/2 семестр/lab3/demo/src/main/java/com/example/demo/product/api/ProductDto.java index 277437f..b161903 100644 --- a/2 семестр/lab3/demo/src/main/java/com/example/demo/product/api/ProductDto.java +++ b/2 семестр/lab3/demo/src/main/java/com/example/demo/product/api/ProductDto.java @@ -17,9 +17,6 @@ public class ProductDto { @NotNull @Min(1) private Double price; - @NotNull - @Min(0) - private Integer count; public Long getId() { return id; @@ -52,12 +49,4 @@ public class ProductDto { public void setPrice(Double price) { this.price = price; } - - public Integer getCount() { - return count; - } - - public void setCount(Integer count) { - this.count = count; - } } diff --git a/2 семестр/lab3/demo/src/main/java/com/example/demo/product/model/ProductEntity.java b/2 семестр/lab3/demo/src/main/java/com/example/demo/product/model/ProductEntity.java index 7146533..a9d2224 100644 --- a/2 семестр/lab3/demo/src/main/java/com/example/demo/product/model/ProductEntity.java +++ b/2 семестр/lab3/demo/src/main/java/com/example/demo/product/model/ProductEntity.java @@ -1,17 +1,17 @@ package com.example.demo.product.model; -import java.util.HashSet; +// import java.util.HashSet; import java.util.Objects; -import java.util.Set; +// import java.util.Set; import com.example.demo.types.model.TypeEntity; -import com.example.demo.ordersproducts.model.OrderProductEntity; +// import com.example.demo.ordersproducts.model.OrderProductEntity; import com.example.demo.core.model.BaseEntity; import jakarta.persistence.Column; import jakarta.persistence.Entity; -import jakarta.persistence.OneToMany; -import jakarta.persistence.OrderBy; +// import jakarta.persistence.OneToMany; +// import jakarta.persistence.OrderBy; import jakarta.persistence.JoinColumn; import jakarta.persistence.ManyToOne; import jakarta.persistence.Table; @@ -26,21 +26,18 @@ public class ProductEntity extends BaseEntity { private TypeEntity type; @Column(nullable = false) private Double price; - @Column(nullable = false) - private Integer count; - @OneToMany(mappedBy = "product") - @OrderBy("id ASC") - private Set orderProducts = new HashSet<>(); + // @OneToMany(mappedBy = "product") + // @OrderBy("id ASC") + // private Set orderProducts = new HashSet<>(); public ProductEntity() { } - public ProductEntity(String name, TypeEntity type, Double price, Integer count) { + public ProductEntity(String name, TypeEntity type, Double price) { this.name = name; this.type = type; this.price = price; - this.count = count; } public String getName() { @@ -67,28 +64,20 @@ public class ProductEntity extends BaseEntity { this.price = price; } - public Integer getCount() { - return count; - } + // public Set getOrderProducts() { + // return orderProducts; + // } - public void setCount(Integer count) { - this.count = count; - } - - public Set getOrderProducts() { - return orderProducts; - } - - public void addOrder(OrderProductEntity orderProduct) { - if (orderProduct.getProduct() != this) { - orderProduct.setProduct(this); - } - orderProducts.add(orderProduct); - } + // public void addOrder(OrderProductEntity orderProduct) { + // if (orderProduct.getProduct() != this) { + // orderProduct.setProduct(this); + // } + // orderProducts.add(orderProduct); + // } @Override public int hashCode() { - return Objects.hash(id, name, type, price, count, orderProducts); + return Objects.hash(id, name, type, price/* , orderProducts*/); } @Override @@ -101,8 +90,7 @@ public class ProductEntity extends BaseEntity { return Objects.equals(other.getId(), id) && Objects.equals(other.getName(), name) && Objects.equals(other.getType(), type) - && Objects.equals(other.getPrice(), price) - && Objects.equals(other.getCount(), count) - && Objects.equals(other.getOrderProducts(), orderProducts); + && Objects.equals(other.getPrice(), price); + // && Objects.equals(other.getOrderProducts(), orderProducts); } } diff --git a/2 семестр/lab3/demo/src/main/java/com/example/demo/product/service/ProductService.java b/2 семестр/lab3/demo/src/main/java/com/example/demo/product/service/ProductService.java index 26bd0c7..4632cf0 100644 --- a/2 семестр/lab3/demo/src/main/java/com/example/demo/product/service/ProductService.java +++ b/2 семестр/lab3/demo/src/main/java/com/example/demo/product/service/ProductService.java @@ -58,7 +58,6 @@ public class ProductService { existsEntity.setName(entity.getName()); existsEntity.setType(entity.getType()); existsEntity.setPrice(entity.getPrice()); - existsEntity.setCount(entity.getCount()); return repository.save(existsEntity); } diff --git a/2 семестр/lab3/demo/src/test/java/com/example/demo/OrderServiceTests.java b/2 семестр/lab3/demo/src/test/java/com/example/demo/OrderServiceTests.java index 84edfc5..5681d8b 100644 --- a/2 семестр/lab3/demo/src/test/java/com/example/demo/OrderServiceTests.java +++ b/2 семестр/lab3/demo/src/test/java/com/example/demo/OrderServiceTests.java @@ -49,9 +49,9 @@ public class OrderServiceTests { removeData(); final var type = typeService.create(new TypeEntity("Пепперони")); - product1 = productService.create(new ProductEntity("test1", type, 399.00, 15)); - product2 = productService.create(new ProductEntity("test2", type, 499.00, 10)); - product3 = productService.create(new ProductEntity("test3", type, 450.50, 5)); + product1 = productService.create(new ProductEntity("test1", type, 399.00)); + product2 = productService.create(new ProductEntity("test2", type, 499.00)); + product3 = productService.create(new ProductEntity("test3", type, 450.50)); user = userService.create(new UserEntity("kruviii", "Павел", "Крылов", "test@test.ru", "11-11-2023", "+79876543210", "qwerty123")); order = orderService.create(user.getId(), new OrderEntity("ул. Северный венец, 32")); orderService.create(user.getId(), new OrderEntity("ул. Северный венец, 32")); @@ -116,7 +116,7 @@ public class OrderServiceTests { @Test void AddOrderProductsTest() { final var type = typeService.create(new TypeEntity("3 сыра")); - final var product = productService.create(new ProductEntity("test1", type, 100.00, 5)); + final var product = productService.create(new ProductEntity("test1", type, 100.00)); Assertions.assertEquals(3, orderService.getOrderProducts(user.getId(), order.getId()).size()); orderService.addOrderProducts(user.getId(), order.getId(), Map.of(product.getId(), 5)); Assertions.assertEquals(4, orderService.getOrderProducts(user.getId(), order.getId()).size()); diff --git a/2 семестр/lab3/demo/src/test/java/com/example/demo/ProductServiceTests.java b/2 семестр/lab3/demo/src/test/java/com/example/demo/ProductServiceTests.java index f6aacc1..37d42f6 100644 --- a/2 семестр/lab3/demo/src/test/java/com/example/demo/ProductServiceTests.java +++ b/2 семестр/lab3/demo/src/test/java/com/example/demo/ProductServiceTests.java @@ -37,9 +37,9 @@ class ProductsServiceTests { final var type3 = typeService.create(new TypeEntity("Сырная")); - product = productService.create(new ProductEntity("test", type, 399.00, 15)); - productService.create(new ProductEntity("test", type2, 499.00, 10)); - productService.create(new ProductEntity("test", type3, 450.50, 5)); + product = productService.create(new ProductEntity("test", type, 399.00)); + productService.create(new ProductEntity("test", type2, 499.00)); + productService.create(new ProductEntity("test", type3, 450.50)); } @AfterEach @@ -62,7 +62,7 @@ class ProductsServiceTests { @Test void createNullableTest() { - final ProductEntity nullableProduct = new ProductEntity(null, type, 399.00, 15);; + final ProductEntity nullableProduct = new ProductEntity(null, type, 399.00);; Assertions.assertThrows(DataIntegrityViolationException.class, () -> productService.create(nullableProduct)); } @@ -72,7 +72,7 @@ class ProductsServiceTests { final String test = "TEST"; final TypeEntity newType = typeService.create(new TypeEntity("Фреш")); final TypeEntity oldType = product.getType(); - final ProductEntity newEntity = productService.update(product.getId(), new ProductEntity(test, newType, 100.00, 15)); + final ProductEntity newEntity = productService.update(product.getId(), new ProductEntity(test, newType, 100.00)); Assertions.assertEquals(3, productService.getAll(0L).size()); Assertions.assertEquals(newEntity, productService.get(product.getId())); Assertions.assertEquals(test, newEntity.getName()); @@ -85,7 +85,7 @@ class ProductsServiceTests { productService.delete(product.getId()); Assertions.assertEquals(2, productService.getAll(0L).size()); - final ProductEntity newEntity = productService.create(new ProductEntity(product.getName(), product.getType(), product.getPrice(), product.getCount())); + final ProductEntity newEntity = productService.create(new ProductEntity(product.getName(), product.getType(), product.getPrice())); Assertions.assertEquals(3, typeService.getAll().size()); Assertions.assertNotEquals(product.getId(), newEntity.getId()); }