diff --git a/backend/ipLab/data.mv.db b/backend/ipLab/data.mv.db index 11dee23..fd1fd43 100644 Binary files a/backend/ipLab/data.mv.db and b/backend/ipLab/data.mv.db differ diff --git a/backend/ipLab/src/main/java/com/example/ipLab/StoreDataBase/Controllers/ProductController.java b/backend/ipLab/src/main/java/com/example/ipLab/StoreDataBase/Controllers/ProductController.java index 624a5c7..593ae0a 100644 --- a/backend/ipLab/src/main/java/com/example/ipLab/StoreDataBase/Controllers/ProductController.java +++ b/backend/ipLab/src/main/java/com/example/ipLab/StoreDataBase/Controllers/ProductController.java @@ -28,6 +28,21 @@ public class ProductController { .toList(); } + //сделать запрос + пагинация + @GetMapping("/getWithStores") + public List getProductsWithStores(){ + return productService.getAllProducts().stream().filter(prod -> prod.getStore() != null) + .map(ProductDTO::new) + .toList(); + } + + @GetMapping("/getWithoutStores") + public List getProductsWithoutStores(){ + return productService.getAllProducts().stream().filter(prod -> prod.getStore() == null) + .map(ProductDTO::new) + .toList(); + } + @PostMapping public ProductDTO createProduct(@RequestParam("productName") String productName){ final Product product = productService.addProduct(productName); diff --git a/backend/ipLab/src/main/java/com/example/ipLab/StoreDataBase/Controllers/StoreController.java b/backend/ipLab/src/main/java/com/example/ipLab/StoreDataBase/Controllers/StoreController.java index 2d3373a..f918377 100644 --- a/backend/ipLab/src/main/java/com/example/ipLab/StoreDataBase/Controllers/StoreController.java +++ b/backend/ipLab/src/main/java/com/example/ipLab/StoreDataBase/Controllers/StoreController.java @@ -44,9 +44,9 @@ public class StoreController { return new StoreDTO(storeService.updateStore(id, storeName)); } - @PutMapping("/{storeId}-{productId}") - public ProductDTO addProduct(@PathVariable Long storeId, - @PathVariable Long productId){ + @PutMapping("/add") + public ProductDTO addProduct(@RequestParam("storeId") Long storeId, + @RequestParam("productId") Long productId){ return new ProductDTO(storeService.addProduct(storeId, productId)); } diff --git a/backend/ipLab/src/main/java/com/example/ipLab/StoreDataBase/DTO/OrderedDTO.java b/backend/ipLab/src/main/java/com/example/ipLab/StoreDataBase/DTO/OrderedDTO.java index d54164c..2eabeec 100644 --- a/backend/ipLab/src/main/java/com/example/ipLab/StoreDataBase/DTO/OrderedDTO.java +++ b/backend/ipLab/src/main/java/com/example/ipLab/StoreDataBase/DTO/OrderedDTO.java @@ -7,12 +7,14 @@ public class OrderedDTO { public final int quantity; public final String productName; public final String customerFIO; + public final String storeName; public OrderedDTO(Ordered ordered){ this.id = ordered.getId(); this.quantity = ordered.getQuantity(); this.productName = ordered.getProduct().getName(); - this.customerFIO = ordered.getCustomer().getLastName() + ordered.getCustomer().getFirstName() + ordered.getCustomer().getMiddleName(); + this.storeName = ordered.getProduct().getStore().getStoreName(); + this.customerFIO = ordered.getCustomer().getLastName() + " " + ordered.getCustomer().getFirstName() + " " + ordered.getCustomer().getMiddleName(); } public Long getId() { @@ -30,4 +32,8 @@ public class OrderedDTO { public String getCustomerFIO() { return customerFIO; } + + public String getStoreName() { + return storeName; + } } diff --git a/backend/ipLab/src/main/java/com/example/ipLab/StoreDataBase/DTO/ProductDTO.java b/backend/ipLab/src/main/java/com/example/ipLab/StoreDataBase/DTO/ProductDTO.java index 6672276..826b2b8 100644 --- a/backend/ipLab/src/main/java/com/example/ipLab/StoreDataBase/DTO/ProductDTO.java +++ b/backend/ipLab/src/main/java/com/example/ipLab/StoreDataBase/DTO/ProductDTO.java @@ -6,13 +6,13 @@ import java.util.List; public class ProductDTO { public final Long id; - public final String name; + public final String productName; public final String storeName; public ProductDTO(Product product){ this.id = product.getId(); - this.name = product.getName(); - this.storeName = product.getStore().getStoreName(); + this.productName = product.getName(); + this.storeName = product.getStore() == null ? null : product.getStore().getStoreName(); } public Long getId() { @@ -20,7 +20,7 @@ public class ProductDTO { } public String getName() { - return name; + return productName; } public String getStoreName() { 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 5f1beb2..f884f69 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 @@ -38,8 +38,10 @@ public class Product { } @PreRemove public void removeStore(){ - this.store.getProducts().remove(this); - this.store = null; + if (this.store != null) { + this.store.getProducts().remove(this); + this.store = null; + } removeOrders(); } 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 0a0ec07..b1b7f1c 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,6 +1,5 @@ package com.example.ipLab.StoreDataBase.Model; -import com.example.ipLab.StoreDataBase.Service.ProductService; import jakarta.persistence.*; import jakarta.validation.constraints.NotBlank; @@ -18,7 +17,9 @@ public class Store { private String storeName; @OneToMany(fetch = FetchType.EAGER, mappedBy = "store", cascade = CascadeType.ALL, orphanRemoval = true) private List products; - public Store(){} + public Store(){ + this.products = new ArrayList<>(); + } public Store(String storeName){ this.storeName = storeName; this.products = new ArrayList<>(); @@ -47,7 +48,7 @@ public class Store { products) { product.removeStore(); } - products = null; + products = new ArrayList<>(); } public void setStoreName(String storeName) { diff --git a/frontend/src/App.jsx b/frontend/src/App.jsx index 2ab1336..869a6bc 100644 --- a/frontend/src/App.jsx +++ b/frontend/src/App.jsx @@ -1,7 +1,10 @@ import { useRoutes, Outlet, BrowserRouter } from 'react-router-dom'; import Header from './components/common/Header'; -import Footer from './components/common/Footer'; -import CustomerPage from './components/pages/customerPage' +import CustomerPage from './components/pages/customerPage'; +import StorePage from './components/pages/storePage'; +import ProductPage from './components/pages/productPage'; +import OrderPage from './components/pages/orderPage'; +import AddToStorePage from './components/pages/addToStorePage' import './styleSite.css'; function Router(props) { @@ -12,9 +15,10 @@ export default function App() { const routes = [ { index: true, element: }, { path: 'customer', element: , label:'Покупатели'}, - // { path: 'shop', element: , label: 'Магазины' }, - // { path: 'product', element: , label: 'Товары'}, - // { path: 'order', element: , label: 'Заказы'} + { path: 'store', element: , label: 'Магазины' }, + { path: 'product', element: , label: 'Товары' }, + { path: 'order', element: , label: 'Заказы'}, + { path: 'addToStore', element: , label: 'Доставка'} ]; const links = routes.filter(route => route.hasOwnProperty('label')); const rootRoute = [ @@ -29,7 +33,6 @@ export default function App() {
-