From c6dff060b0a1f1af93597f57204ae62554104ad5 Mon Sep 17 00:00:00 2001 From: abazov73 <92822431+abazov73@users.noreply.github.com> Date: Tue, 11 Apr 2023 12:51:22 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A2=D1=80=D0=B5=D1=82=D1=8C=D1=8F=20=D0=BB?= =?UTF-8?q?=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82=D0=BE=D1=80=D0=BD=D0=B0?= =?UTF-8?q?=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0.=20=D0=A4=D0=B8?= =?UTF-8?q?=D0=BA=D1=81=20=D1=81=D0=B5=D1=80=D0=B2=D0=B8=D1=81=D0=B0=20?= =?UTF-8?q?=D0=BF=D1=80=D0=BE=D0=B4=D1=83=D0=BA=D1=82=D0=B0=20+=20=D1=84?= =?UTF-8?q?=D0=B8=D0=BA=D1=81=20=D1=83=D1=81=D1=82=D0=B0=D0=BD=D0=BE=D0=B2?= =?UTF-8?q?=D0=BA=D0=B8=20=D1=81=D0=B2=D1=8F=D0=B7=D0=B5=D0=B9=20OneToMany?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/ipLab/data.mv.db | Bin 57344 -> 61440 bytes .../ipLab/StoreDataBase/Model/Customer.java | 7 +- .../ipLab/StoreDataBase/Model/Ordered.java | 13 +++- .../ipLab/StoreDataBase/Model/Product.java | 6 ++ .../ipLab/StoreDataBase/Model/Store.java | 13 ++++ .../StoreDataBase/Service/OrderService.java | 8 +- .../StoreDataBase/Service/ProductService.java | 72 ++++++++++++++++++ .../StoreDataBase/Service/StoreService.java | 63 ++++++--------- .../test/java/com/example/ipLab/JpaTests.java | 23 ++++-- 9 files changed, 150 insertions(+), 55 deletions(-) create mode 100644 backend/ipLab/src/main/java/com/example/ipLab/StoreDataBase/Service/ProductService.java diff --git a/backend/ipLab/data.mv.db b/backend/ipLab/data.mv.db index 86807f4f537ea656b588aa7b7cf3166957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zsGL8a!ZUvXpddX~)|;t#KD9C37I`>f14(2T{cH*o>fNhxIFDJ+l2qo}K+gX!BqmDL zfBakg1rqx|IsZQotN?QUzXT-H;veON!>c!e5*c2-46mCJ75V>1`|oJ~??n55M}_^r JxB&bA{|69O2owMS diff --git a/backend/ipLab/src/main/java/com/example/ipLab/StoreDataBase/Model/Customer.java b/backend/ipLab/src/main/java/com/example/ipLab/StoreDataBase/Model/Customer.java index cbf92db..6605858 100644 --- a/backend/ipLab/src/main/java/com/example/ipLab/StoreDataBase/Model/Customer.java +++ b/backend/ipLab/src/main/java/com/example/ipLab/StoreDataBase/Model/Customer.java @@ -19,7 +19,12 @@ public class Customer { private String middleName; @OneToMany(fetch = FetchType.EAGER, mappedBy = "customer", cascade = CascadeType.ALL) private List orders; - + public void AddOrdered(Ordered ordered){ + this.orders.add(ordered); + if (ordered.getCustomer() != this){ + ordered.setCustomer(this); + } + } public Customer(){} public Customer(String lastName, String firstName, String middleName){ diff --git a/backend/ipLab/src/main/java/com/example/ipLab/StoreDataBase/Model/Ordered.java b/backend/ipLab/src/main/java/com/example/ipLab/StoreDataBase/Model/Ordered.java index f307076..007dd5b 100644 --- a/backend/ipLab/src/main/java/com/example/ipLab/StoreDataBase/Model/Ordered.java +++ b/backend/ipLab/src/main/java/com/example/ipLab/StoreDataBase/Model/Ordered.java @@ -20,10 +20,7 @@ public class Ordered { @Column private int quantity; public Ordered(){} - public Ordered(Store store, Product product, Customer customer, int quantity){ - this.store = store; - this.product = product; - this.customer = customer; + public Ordered(int quantity){ this.quantity = quantity; } @@ -55,6 +52,14 @@ public class Ordered { this.quantity = quantity; } + public void setStore(Store store) { + this.store = store; + } + + public void setCustomer(Customer customer) { + this.customer = customer; + } + @Override public boolean equals(Object obj) { if (this == obj) return true; diff --git a/backend/ipLab/src/main/java/com/example/ipLab/StoreDataBase/Model/Product.java b/backend/ipLab/src/main/java/com/example/ipLab/StoreDataBase/Model/Product.java index 53c0980..70cf9d0 100644 --- a/backend/ipLab/src/main/java/com/example/ipLab/StoreDataBase/Model/Product.java +++ b/backend/ipLab/src/main/java/com/example/ipLab/StoreDataBase/Model/Product.java @@ -28,6 +28,12 @@ public class Product { this.name = name; this.orders = new ArrayList(); } + public void AddOrdered(Ordered ordered){ + this.orders.add(ordered); + if (ordered.getProduct() != this){ + ordered.setProduct(this); + } + } public Long getId() { return id; diff --git a/backend/ipLab/src/main/java/com/example/ipLab/StoreDataBase/Model/Store.java b/backend/ipLab/src/main/java/com/example/ipLab/StoreDataBase/Model/Store.java index 130974e..b9ddadb 100644 --- a/backend/ipLab/src/main/java/com/example/ipLab/StoreDataBase/Model/Store.java +++ b/backend/ipLab/src/main/java/com/example/ipLab/StoreDataBase/Model/Store.java @@ -1,5 +1,6 @@ package com.example.ipLab.StoreDataBase.Model; +import com.example.ipLab.StoreDataBase.Service.ProductService; import jakarta.persistence.*; import java.util.ArrayList; @@ -39,6 +40,18 @@ public class Store { public List getProducts() { return products; } + public void AddProduct(Product product){ + this.products.add(product); + if (product.getStore() != this){ + product.setStore(this); + } + } + public void AddOrdered(Ordered ordered){ + this.orders.add(ordered); + if (ordered.getStore() != this){ + ordered.setStore(this); + } + } public void setStoreName(String storeName) { this.storeName = storeName; diff --git a/backend/ipLab/src/main/java/com/example/ipLab/StoreDataBase/Service/OrderService.java b/backend/ipLab/src/main/java/com/example/ipLab/StoreDataBase/Service/OrderService.java index ea29793..7f2d506 100644 --- a/backend/ipLab/src/main/java/com/example/ipLab/StoreDataBase/Service/OrderService.java +++ b/backend/ipLab/src/main/java/com/example/ipLab/StoreDataBase/Service/OrderService.java @@ -20,10 +20,10 @@ public class OrderService { @Transactional public Ordered addOrder(Store store, Product product, Customer customer, int quantity){ - final Ordered order = new Ordered(store, product, customer, quantity); - order.getStore().getOrders().add(order); - order.getCustomer().getOrders().add(order); - order.getProduct().getOrders().add(order); + final Ordered order = new Ordered(quantity); + product.AddOrdered(order); + customer.AddOrdered(order); + store.AddOrdered(order); em.persist(order); return order; } diff --git a/backend/ipLab/src/main/java/com/example/ipLab/StoreDataBase/Service/ProductService.java b/backend/ipLab/src/main/java/com/example/ipLab/StoreDataBase/Service/ProductService.java new file mode 100644 index 0000000..9ba3db5 --- /dev/null +++ b/backend/ipLab/src/main/java/com/example/ipLab/StoreDataBase/Service/ProductService.java @@ -0,0 +1,72 @@ +package com.example.ipLab.StoreDataBase.Service; + +import com.example.ipLab.StoreDataBase.Model.Customer; +import com.example.ipLab.StoreDataBase.Model.Ordered; +import com.example.ipLab.StoreDataBase.Model.Product; +import com.example.ipLab.StoreDataBase.Model.Store; +import jakarta.persistence.EntityManager; +import jakarta.persistence.EntityNotFoundException; +import jakarta.persistence.PersistenceContext; +import jakarta.transaction.Transactional; +import org.springframework.stereotype.Service; +import org.springframework.util.StringUtils; + +import java.util.List; +@Service +public class ProductService { + @PersistenceContext + private EntityManager em; + @Transactional + public Product addProduct(String productName){ + if (!StringUtils.hasText(productName)){ + throw new IllegalArgumentException("Product name is null or empty"); + } + final Product product = new Product(productName); + em.persist(product); + return product; + } + + @Transactional() + public Product getProduct(Long id){ + Product product = em.find(Product.class, id); + if (product == null){ + throw new EntityNotFoundException(String.format("Product with id = %s isn't found", id)); + } + em.persist(product); + return product; + } + + @Transactional + public List getAllProducts(){ + return em.createQuery("get p from Product p", Product.class).getResultList(); + } + + @Transactional + public Product updateProduct(Long id, String productName){ + if (!StringUtils.hasText(productName)){ + throw new IllegalArgumentException("Product name is null or empty"); + } + final Product product = getProduct(id); + if (product == null){ + throw new EntityNotFoundException(String.format("Product with id = %s isn't found", id)); + } + product.setName(productName); + return em.merge(product); + } + + @Transactional + public Product deleteProduct(Long id){ + final Product product = getProduct(id); + if (product == null){ + throw new EntityNotFoundException(String.format("Product with id = %s isn't found", id)); + } + Store store = product.getStore(); + if (store != null) store.getProducts().remove(product); + em.remove(product); + return product; + } + @Transactional + public void deleteAllProducts(){ + em.createQuery("delete from Customer"); + } +} diff --git a/backend/ipLab/src/main/java/com/example/ipLab/StoreDataBase/Service/StoreService.java b/backend/ipLab/src/main/java/com/example/ipLab/StoreDataBase/Service/StoreService.java index 04f142d..3622cc8 100644 --- a/backend/ipLab/src/main/java/com/example/ipLab/StoreDataBase/Service/StoreService.java +++ b/backend/ipLab/src/main/java/com/example/ipLab/StoreDataBase/Service/StoreService.java @@ -16,6 +16,11 @@ import java.util.List; public class StoreService { @PersistenceContext private EntityManager em; + private ProductService productService; + + public StoreService(ProductService productService){ + this.productService = productService; + } @Transactional public Store addStore(String storeName){ @@ -64,69 +69,45 @@ public class StoreService { //product section @Transactional - public Product addProduct(Long storeId, String productName){ - if (!StringUtils.hasText(productName)){ - throw new IllegalArgumentException("Product name is null or empty"); - } - Store store = em.find(Store.class, storeId); - if (store == null){ - throw new EntityNotFoundException(String.format("Store with id = %s isn't found", storeId)); - } - final Product product = new Product(productName); - em.persist(product); - store.getProducts().add(product); - product.setStore(store); + public Product addProduct(Long storeId, Long productId){ + Store store = getStore(storeId); + Product product = productService.getProduct(productId); + store.AddProduct(product); + em.persist(store); return product; } @Transactional() - public Product getProduct(Long productId, Long storeId){ - Store store = em.find(Store.class, storeId); + public Product getProductFromStore(Long productId, Long storeId){ + Store store = getStore(storeId); var prFind = store.getProducts().stream().filter(pr -> pr.getId().equals(productId)).findFirst(); if (prFind.isPresent()) { return prFind.get(); } - else throw new EntityNotFoundException(String.format("Product with id = %s isn't found", productId)); + else throw new EntityNotFoundException(String.format("Product with id = %s isn't found in store with id = %s", productId, storeId)); } @Transactional - public List getAllProducts(Long storeId){ - return em.find(Store.class, storeId).getProducts(); + public List getAllProductsFromStore(Long storeId) { + Store store = getStore(storeId); + return store.getProducts(); } @Transactional - public Product updateProduct(Long storeId, Long productId, String productName){ - if (!StringUtils.hasText(productName)){ - throw new IllegalArgumentException("Product name is null or empty"); - } - final Product product = getProduct(productId, storeId); - if (product == null){ - throw new EntityNotFoundException(String.format("Product with id = %s isn't found", productId)); - } - product.setName(productName); - return em.merge(product); - } - - @Transactional - public Product deleteProduct(Long storeId, Long productId){ - final Product product = getProduct(productId, storeId); - if (product == null){ - throw new EntityNotFoundException(String.format("Product with id = %s isn't found", productId)); - } - Store store = product.getStore(); - if (store != null) store.getProducts().remove(product); + public Product deleteProductFromStore(Long storeId, Long productId){ + Store store = getStore(storeId); + Product product = getProductFromStore(productId, storeId); + store.getProducts().remove(product); em.remove(product); return product; } @Transactional public void deleteAllProducts(Long storeId){ - Store store = em.find(Store.class, storeId); - if (store == null){ - throw new EntityNotFoundException(String.format("Store with id = %s isn't found", storeId)); - } + Store store = getStore(storeId); List storeProducts = store.getProducts(); for (Product pr: storeProducts) { + pr.setStore(null); store.getProducts().remove(pr); em.remove(pr); } diff --git a/backend/ipLab/src/test/java/com/example/ipLab/JpaTests.java b/backend/ipLab/src/test/java/com/example/ipLab/JpaTests.java index 3bad1fb..ca5b5de 100644 --- a/backend/ipLab/src/test/java/com/example/ipLab/JpaTests.java +++ b/backend/ipLab/src/test/java/com/example/ipLab/JpaTests.java @@ -6,6 +6,7 @@ import com.example.ipLab.StoreDataBase.Model.Product; import com.example.ipLab.StoreDataBase.Model.Store; import com.example.ipLab.StoreDataBase.Service.CustomerService; import com.example.ipLab.StoreDataBase.Service.OrderService; +import com.example.ipLab.StoreDataBase.Service.ProductService; import com.example.ipLab.StoreDataBase.Service.StoreService; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -20,8 +21,11 @@ public class JpaTests { CustomerService customerService; @Autowired StoreService storeService; + @Autowired + ProductService productService; @Test void testStore(){ + productService.deleteAllProducts(); orderService.deleteAllOrders(); customerService.deleteAllCustomers(); storeService.deleteAllStores(); @@ -32,6 +36,7 @@ public class JpaTests { storeService.updateStore(store.getId(), "newName"); Assertions.assertEquals("newName", storeService.getStore(store.getId()).getStoreName()); Assertions.assertEquals("newName", storeService.deleteStore(store.getId()).getStoreName()); + productService.deleteAllProducts(); orderService.deleteAllOrders(); customerService.deleteAllCustomers(); storeService.deleteAllStores(); @@ -39,6 +44,7 @@ public class JpaTests { @Test void testCustomer(){ + productService.deleteAllProducts(); orderService.deleteAllOrders(); customerService.deleteAllCustomers(); storeService.deleteAllStores(); @@ -49,6 +55,7 @@ public class JpaTests { Assertions.assertEquals("1", customerService.updateCustomer(c.getId(), c.getLastName(), "1", c.getMiddleName()).getFirstName()); Assertions.assertEquals("1", customerService.deleteCustomer(c.getId()).getFirstName()); + productService.deleteAllProducts(); orderService.deleteAllOrders(); customerService.deleteAllCustomers(); storeService.deleteAllStores(); @@ -56,6 +63,7 @@ public class JpaTests { @Test void testProduct(){ + productService.deleteAllProducts(); orderService.deleteAllOrders(); customerService.deleteAllCustomers(); storeService.deleteAllStores(); @@ -63,13 +71,15 @@ public class JpaTests { Store store = storeService.addStore("example"); Assertions.assertEquals("example", store.getStoreName()); - Product p = storeService.addProduct(store.getId(), "product"); + Product p = productService.addProduct("product"); Assertions.assertEquals("product", p.getName()); - Assertions.assertEquals("product", storeService.getProduct(p.getId(), store.getId()).getName()); - Assertions.assertEquals("productUpd", storeService.updateProduct(store.getId(), p.getId(), "productUpd").getName()); - Assertions.assertEquals("productUpd", storeService.deleteProduct(store.getId(), p.getId()).getName()); + Assertions.assertEquals("product", storeService.addProduct(store.getId(), p.getId()).getName()); + Assertions.assertEquals("product", storeService.getProductFromStore(p.getId(), store.getId()).getName()); + Assertions.assertEquals("productUpd", productService.updateProduct(p.getId(), "productUpd").getName()); + Assertions.assertEquals("productUpd", storeService.deleteProductFromStore(store.getId(), p.getId()).getName()); + productService.deleteAllProducts(); orderService.deleteAllOrders(); customerService.deleteAllCustomers(); storeService.deleteAllStores(); @@ -77,6 +87,7 @@ public class JpaTests { @Test void testOrder(){ + productService.deleteAllProducts(); orderService.deleteAllOrders(); customerService.deleteAllCustomers(); storeService.deleteAllStores(); @@ -84,7 +95,8 @@ public class JpaTests { Store store = storeService.addStore("example"); Assertions.assertEquals("example", store.getStoreName()); - Product p = storeService.addProduct(store.getId(), "product"); + Product p = productService.addProduct("product"); + storeService.addProduct(store.getId(), p.getId()); Assertions.assertEquals("product", p.getName()); Customer c = customerService.addCustomer("1", "2", "3"); @@ -97,6 +109,7 @@ public class JpaTests { Assertions.assertEquals("6", Integer.toString(orderService.updateOrder(order.getId(), 6).getQuantity())); Assertions.assertEquals("6", Integer.toString(orderService.deleteOrder(order.getId()).getQuantity())); + productService.deleteAllProducts(); orderService.deleteAllOrders(); customerService.deleteAllCustomers(); storeService.deleteAllStores();