оказывается дата уже была в миллисекундах (╯°□°)╯

This commit is contained in:
Ino 2023-04-28 13:06:01 +04:00
parent 2b40c29f36
commit a9112f5e06
7 changed files with 34 additions and 23 deletions

View File

@ -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 {

View File

@ -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);
}

View File

@ -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;

View File

@ -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
}

View File

@ -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(
<div className="container">
<div className="row">
@ -123,14 +141,14 @@ export default function CreateOrderPage(props){
<p className="h4">Продукты</p>
<div className="btn-group" role="group" aria-label="Basic mixed styles example">
<button type="button" className="btn btn-success" onClick={addProduct}>Добавить продукт</button>
<button type="button" className="btn btn-danger" >Удалить продукт</button>
<button type="button" className="btn btn-danger" onClick={removeProduct} >Удалить продукт</button>
</div>
<Table
headers={headers}
items={order.products}
selectable={true}
onClick={ds}
onClick={handleTableClick}
onDblClick={ds}/>
<Modal

View File

@ -24,15 +24,19 @@ export default function OrderPage(){
const loadItems = () => {
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) =>{}

View File

@ -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 = () => {