diff --git a/front/src/App.jsx b/front/src/App.jsx index 1460fe4..58dfdfd 100644 --- a/front/src/App.jsx +++ b/front/src/App.jsx @@ -5,6 +5,7 @@ import Footer from "./components/common/Footer"; import CatalogStudents from './components/catalogs/CatalogStudents'; import Menu from './components/catalogs/Menu'; import Basket from './components/catalogs/Basket'; +import History from './components/catalogs/History'; import { useState } from 'react'; function Router(props) { @@ -17,7 +18,8 @@ export default function App() { { index: true, element: }, { path: "catalogs/menu", element: , label: "Меню" }, { path: "catalogs/component", element: , label: "Компоненты" }, - { path: "catalogs/basket", element: , label: "Корзина" } + { path: "catalogs/basket", element: , label: "Корзина" }, + { path: "catalogs/history", element: , label: "История" } ]; const links = routes.filter(route => route.hasOwnProperty('label')); const rootRoute = [ diff --git a/front/src/components/catalogs/CatalogHistory.jsx b/front/src/components/catalogs/CatalogHistory.jsx new file mode 100644 index 0000000..5b4fca8 --- /dev/null +++ b/front/src/components/catalogs/CatalogHistory.jsx @@ -0,0 +1,66 @@ +import { useState, useEffect } from "react"; +import Table from "../common/Table"; +import Modal from "../common/Modal"; +import DataService from '../../services/DataService'; + +export default function CatalogHistory(props) { + const [items, setItems] = useState([]); + const [modalHeader, setModalHeader] = useState(''); + const [modalConfirm, setModalConfirm] = useState(''); + const [modalVisible, setModalVisible] = useState(false); + const [isEdit, setEdit] = useState(false); + + + useEffect(() => { + loadItems(); + }, []); + + function loadItems() { + DataService.readAll(props.getAllUrl, props.transformer) + .then(data => setItems(data)); + } + + function saveItem() { + if (!isEdit) { + DataService.create(props.getAllUrl, props.data).then(() => loadItems()); + } else { + DataService.update(props.url + props.data.id, props.data).then(() => loadItems()); + } + } + + function edit(editedId) { + DataService.read(props.url + editedId, props.transformer) + .then(data => { + setEdit(true); + setModalHeader('Редактирование элемента'); + setModalConfirm('Сохранить'); + setModalVisible(true); + props.onEdit(data); + }); + } + + function handleModalHide() { + setModalVisible(false); + } + + function handleModalDone() { + saveItem(); + } + + return ( + <> + + + {props.children} + + + ); +} \ No newline at end of file diff --git a/front/src/components/catalogs/History.jsx b/front/src/components/catalogs/History.jsx new file mode 100644 index 0000000..9ba8407 --- /dev/null +++ b/front/src/components/catalogs/History.jsx @@ -0,0 +1,54 @@ +import { useState, useEffect } from 'react'; +import Catalog from './CatalogHistory'; +import Component from '../../models/Component'; +import DataService from '../../services/DataService'; +import Order from '../../models/Order'; + +export default function CatalogStudents(props) { + const getAllUrl = '/order'; + const url = '/order/'; + const transformer = (data) => new Order(data); + const catalogStudHeaders = [ + { name: 'date', label: 'Дата оформления' }, + { name: 'price', label: 'Общая стоимость' }, + { name: 'status', label: 'Статус' } + ]; + + const [data, setData] = useState(new Order()); + + function handleOnAdd() { + setData(new Order()); + } + + function handleOnEdit(data) { + setData(new Order(data)); + } + + function handleFormChange(event) { + setData({ ...data, [event.target.id]: event.target.value }) + } + + return ( +
+ +
+ + +
+
+ + +
+
+
+ ); +} \ No newline at end of file diff --git a/front/src/components/common/TableOrder.jsx b/front/src/components/common/TableOrder.jsx index 483f64f..f9a5d18 100644 --- a/front/src/components/common/TableOrder.jsx +++ b/front/src/components/common/TableOrder.jsx @@ -43,13 +43,8 @@ export default function TableOrder(props) { loadItems(); } } - async function needWait(){ - setOrder({...order, ["price"]:cost}); - } async function acceptOrder(){ - await needWait(); - - await DataService.create("/order",order ).then(data => { + await DataService.create("/order",{...order, ["price"]:cost, ["status"]: "1"} ).then(data => { props.setProduct([]); setCost(0); }); diff --git a/front/src/models/Order.js b/front/src/models/Order.js index d7588b5..d3e2fa7 100644 --- a/front/src/models/Order.js +++ b/front/src/models/Order.js @@ -4,5 +4,6 @@ export default class Order { this.date = data?.date || ""; this.price = data?.price || 0; this.productDTOList = data?.productDTOList || []; + this.status = data?.status || "0"; } } \ No newline at end of file diff --git a/src/main/java/ip/labwork/WebConfiguration.java b/src/main/java/ip/labwork/WebConfiguration.java index 1391886..29b08a4 100644 --- a/src/main/java/ip/labwork/WebConfiguration.java +++ b/src/main/java/ip/labwork/WebConfiguration.java @@ -1,8 +1,15 @@ package ip.labwork; +import org.springframework.boot.web.server.ErrorPage; +import org.springframework.boot.web.server.WebServerFactoryCustomizer; +import org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory; +import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.web.servlet.config.annotation.CorsRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; +import org.springframework.web.servlet.config.annotation.ViewControllerRegistration; +import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; +import org.springframework.http.HttpStatus; @Configuration class WebConfiguration implements WebMvcConfigurer { @@ -10,4 +17,17 @@ class WebConfiguration implements WebMvcConfigurer { public void addCorsMappings(CorsRegistry registry){ registry.addMapping("/**").allowedMethods("*"); } + @Override + public void addViewControllers(ViewControllerRegistry registry) { + ViewControllerRegistration registration = registry.addViewController("/notFound"); + registration.setViewName("forward:/index.html"); + registration.setStatusCode(HttpStatus.OK); + } + + @Bean + public WebServerFactoryCustomizer containerCustomizer() { + return container -> { + container.addErrorPages(new ErrorPage(HttpStatus.NOT_FOUND, "/notFound")); + }; + } } diff --git a/src/main/java/ip/labwork/shop/controller/OrderDTO.java b/src/main/java/ip/labwork/shop/controller/OrderDTO.java index 75895c6..ef9305d 100644 --- a/src/main/java/ip/labwork/shop/controller/OrderDTO.java +++ b/src/main/java/ip/labwork/shop/controller/OrderDTO.java @@ -1,6 +1,7 @@ package ip.labwork.shop.controller; import ip.labwork.shop.model.Order; +import ip.labwork.shop.model.OrderStatus; import java.util.Date; import java.util.List; @@ -10,6 +11,7 @@ public class OrderDTO { private long id; private Date date = new Date(); private int price; + private OrderStatus status = OrderStatus.Неизвестен; private List productDTOList; public OrderDTO(Order order) { this.id = order.getId(); @@ -19,6 +21,7 @@ public class OrderDTO { .filter(x -> Objects.equals(x.getId().getOrderId(), order.getId())) .map(y -> new ProductDTO(y.getProduct(), y.getCount())) .toList(); + this.status = Objects.equals(order.getStatus().toString(), "") ? OrderStatus.Неизвестен : order.getStatus(); } public OrderDTO() { @@ -44,6 +47,14 @@ public class OrderDTO { this.date = date; } + public OrderStatus getStatus() { + return status; + } + + public void setStatus(OrderStatus status) { + this.status = status; + } + public List getProductDTOList() { return productDTOList; } diff --git a/src/main/java/ip/labwork/shop/model/Order.java b/src/main/java/ip/labwork/shop/model/Order.java index 9feed15..9b0e535 100644 --- a/src/main/java/ip/labwork/shop/model/Order.java +++ b/src/main/java/ip/labwork/shop/model/Order.java @@ -22,13 +22,15 @@ public class Order { private Integer price; @OneToMany(mappedBy = "order", cascade = CascadeType.ALL, fetch = FetchType.EAGER) private List products; + private OrderStatus status; public Order(){ } - public Order(Date date, Integer price) { + public Order(Date date, Integer price, OrderStatus status) { this.date = date; this.price = price; + this.status = status; } public Long getId() { @@ -74,6 +76,14 @@ public class Order { this.products.remove(orderProducts); } + public OrderStatus getStatus() { + return status; + } + + public void setStatus(OrderStatus status) { + this.status = status; + } + @Override public boolean equals(Object o) { if (this == o) return true; diff --git a/src/main/java/ip/labwork/shop/model/OrderStatus.java b/src/main/java/ip/labwork/shop/model/OrderStatus.java new file mode 100644 index 0000000..e96057f --- /dev/null +++ b/src/main/java/ip/labwork/shop/model/OrderStatus.java @@ -0,0 +1,5 @@ +package ip.labwork.shop.model; + +public enum OrderStatus { + Неизвестен, Готов +} \ No newline at end of file diff --git a/src/main/java/ip/labwork/shop/service/OrderService.java b/src/main/java/ip/labwork/shop/service/OrderService.java index 63ef9fd..02a2f57 100644 --- a/src/main/java/ip/labwork/shop/service/OrderService.java +++ b/src/main/java/ip/labwork/shop/service/OrderService.java @@ -31,7 +31,7 @@ public class OrderService { for(int i = 0; i < orderDTO.getProductDTOList().size(); i++){ price += orderDTO.getProductDTOList().get(i).getPrice() * orderDTO.getProductDTOList().get(i).getCount(); } - final Order order = new Order(new Date(), price); + final Order order = new Order(new Date(), price, orderDTO.getStatus()); validatorUtil.validate(order); orderRepository.save(order); for (int i = 0; i < orderDTO.getProductDTOList().size(); i++) { @@ -49,7 +49,7 @@ public class OrderService { for(int i = 0; i < orderDTO.getProductDTOList().size(); i++){ price += orderDTO.getProductDTOList().get(i).getPrice() * orderDTO.getProductDTOList().get(i).getCount(); } - final Order order = new Order(new Date(), price); + final Order order = new Order(new Date(), price, orderDTO.getStatus()); orderDTO.setDate(order.getDate()); orderDTO.setPrice(price); validatorUtil.validate(order);