From a9112f5e064156610652b2ca9742963c99260818 Mon Sep 17 00:00:00 2001 From: Ino Date: Fri, 28 Apr 2023 13:06:01 +0400 Subject: [PATCH] =?UTF-8?q?=D0=BE=D0=BA=D0=B0=D0=B7=D1=8B=D0=B2=D0=B0?= =?UTF-8?q?=D0=B5=D1=82=D1=81=D1=8F=20=D0=B4=D0=B0=D1=82=D0=B0=20=D1=83?= =?UTF-8?q?=D0=B6=D0=B5=20=D0=B1=D1=8B=D0=BB=D0=B0=20=D0=B2=20=D0=BC=D0=B8?= =?UTF-8?q?=D0=BB=D0=BB=D0=B8=D1=81=D0=B5=D0=BA=D1=83=D0=BD=D0=B4=D0=B0?= =?UTF-8?q?=D1=85=20(=E2=95=AF=C2=B0=E2=96=A1=C2=B0)=E2=95=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../example/demo/supply/Order/OrderDto.java | 2 +- .../demo/supply/Order/OrderService.java | 4 +-- .../com/example/demo/supply/Order/_Order.java | 2 +- front/src/DataService.js | 2 -- front/src/Pages/CreateOrderPage.jsx | 28 +++++++++++++++---- front/src/Pages/OrdersPage.jsx | 9 ++++-- front/src/general/Catalog.jsx | 10 +------ 7 files changed, 34 insertions(+), 23 deletions(-) diff --git a/demo/src/main/java/com/example/demo/supply/Order/OrderDto.java b/demo/src/main/java/com/example/demo/supply/Order/OrderDto.java index 17dfeec..970e3c4 100644 --- a/demo/src/main/java/com/example/demo/supply/Order/OrderDto.java +++ b/demo/src/main/java/com/example/demo/supply/Order/OrderDto.java @@ -4,7 +4,7 @@ import com.example.demo.supply.Product.Product; import com.example.demo.supply.Supplier.Supplier; -import java.sql.Date; +import java.util.Date; import java.util.List; public class OrderDto { diff --git a/demo/src/main/java/com/example/demo/supply/Order/OrderService.java b/demo/src/main/java/com/example/demo/supply/Order/OrderService.java index bc29baf..b61dfb0 100644 --- a/demo/src/main/java/com/example/demo/supply/Order/OrderService.java +++ b/demo/src/main/java/com/example/demo/supply/Order/OrderService.java @@ -6,7 +6,7 @@ import com.example.demo.supply.Supplier.SupplierService; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.sql.Date; +import java.util.Date; import java.util.List; import java.util.Optional; @@ -28,7 +28,7 @@ public class OrderService { @Transactional public _Order addOrder(Long supplierId){ - final _Order order = new _Order(new Date(System.currentTimeMillis())); + final _Order order = new _Order(new Date()); order.setSupplier(supplierService.findSupplier(supplierId)); return orderRepository.save(order); } diff --git a/demo/src/main/java/com/example/demo/supply/Order/_Order.java b/demo/src/main/java/com/example/demo/supply/Order/_Order.java index 29741a5..58a1061 100644 --- a/demo/src/main/java/com/example/demo/supply/Order/_Order.java +++ b/demo/src/main/java/com/example/demo/supply/Order/_Order.java @@ -6,7 +6,7 @@ import com.fasterxml.jackson.annotation.JsonIgnore; import jakarta.persistence.*; -import java.sql.Date; +import java.util.Date; import java.util.ArrayList; import java.util.List; import java.util.Objects; diff --git a/front/src/DataService.js b/front/src/DataService.js index 7cd5077..033756a 100644 --- a/front/src/DataService.js +++ b/front/src/DataService.js @@ -24,7 +24,6 @@ export default class DataService { static async readAll(url, transformer) { const response = await axios.get(this.mainUrl + url); - //console.log(response) return response.data.map(item => transformer(item)); } @@ -42,7 +41,6 @@ export default class DataService { static async create(url, data) { const response = await axios.post(getFullUrl(this.mainUrl + url, data)) const res = response.data - //console.log(res) return res } diff --git a/front/src/Pages/CreateOrderPage.jsx b/front/src/Pages/CreateOrderPage.jsx index c689918..7863f64 100644 --- a/front/src/Pages/CreateOrderPage.jsx +++ b/front/src/Pages/CreateOrderPage.jsx @@ -12,6 +12,8 @@ export default function CreateOrderPage(props){ const supplierUrl = 'supplier/' const productUrl = 'product/' + let selectedItems = []; + const headers = [ { name: 'name', label: 'Продукт' }, { name: 'cost', label: 'Цена' } @@ -71,6 +73,23 @@ export default function CreateOrderPage(props){ }) } + const removeProduct = () => { + if (selectedItems.length === 0) { + return; + } + + if (window.confirm('Удалить выбранные элементы?')) { + const promises = []; + selectedItems.forEach(item => { + promises.push(DataService.delete(props.url + item)); + }); + Promise.all(promises).then((results) => { + selectedItems.length = 0; + loadItems(); + }); + } + } + const handleFormChange = (event) => { setOrder({ ...order, [event.target.id]: event.target.value }) } @@ -87,11 +106,10 @@ export default function CreateOrderPage(props){ } const hideModal = () => setModalVisible(false) - const modalDone = () => { - - } const ds = () => console.log("") + const handleTableClick = (tableSelectedItems) => selectedItems = tableSelectedItems; + return(
@@ -123,14 +141,14 @@ export default function CreateOrderPage(props){

Продукты

- +
{ DataService.getOrders(url).then(data => { - // console.log(data) setOrders([]) data.map(order => { + const date = new Date(order.dateOfOrder) + order.dateOfOrder = `${date.getDate()}-${date.getMonth()}-${date.getFullYear()}` setOrders(prevState => [...prevState, new Order(order)]) }) }) } - const add = () => loadItems() + const add = () => { + console.log("add") + loadItems() + } const edit = () =>{} const remove = () =>{ @@ -51,7 +55,6 @@ export default function OrderPage(){ } } - const handleTableClick = (tableSelectedItems) => {selectedItems = tableSelectedItems;} const handleTableDblClick = (tableSelectedItem) =>{} diff --git a/front/src/general/Catalog.jsx b/front/src/general/Catalog.jsx index cc99ed2..a7dddd5 100644 --- a/front/src/general/Catalog.jsx +++ b/front/src/general/Catalog.jsx @@ -28,18 +28,10 @@ function Catalog(props) { } const saveItem = () => { - if(isAddProd){ - DataService.addProduct(`${props.url}addProduct/${props.data.id}`).then(() => loadItems()) - - } - if (!isEdit) { DataService.create(props.url, props.data).then(() => loadItems()) - if(isAddProd) - DataService.addProduct(`${props.url}addProduct/${props.data.id}`).then(() => loadItems()) - } else{ + } else DataService.update(props.url + props.data.id, props.data).then(() => loadItems()) - } } const add = () => {