~_~
This commit is contained in:
parent
09dd2f7ae2
commit
ac0427a16e
@ -35,10 +35,10 @@ public class OrderController {
|
||||
return new OrderDto(orderService.addProduct(id, productId));
|
||||
}
|
||||
|
||||
@PatchMapping("/{id}")
|
||||
public Orders updateOrder(@PathVariable Long id,
|
||||
@RequestParam() Long supplierId) {
|
||||
return orderService.updateOrder(id, supplierId);
|
||||
@PatchMapping("/removeProduct/{id}/")
|
||||
public OrderDto removeProduct(@PathVariable Long id,
|
||||
@RequestParam() Long productId){
|
||||
return new OrderDto(orderService.removeProduct(id, productId));
|
||||
}
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
|
@ -14,7 +14,7 @@ public class OrderDto {
|
||||
private Supplier supplier;
|
||||
private List<Product> products;
|
||||
|
||||
public OrderDto(Orders order){
|
||||
public OrderDto(_Order order){
|
||||
this.id = order.getId();
|
||||
this.dateOfOrder = order.getDateOfOrder();
|
||||
this.supplier = order.getSupplier();
|
||||
|
@ -2,5 +2,5 @@ package com.example.demo.supply.Order;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
public interface OrderRepository extends JpaRepository<Orders, Long> {
|
||||
public interface OrderRepository extends JpaRepository<_Order, Long> {
|
||||
}
|
||||
|
@ -1,15 +1,11 @@
|
||||
package com.example.demo.supply.Order;
|
||||
|
||||
import com.example.demo.supply.Product.Product;
|
||||
import com.example.demo.supply.Product.ProductRepository;
|
||||
import com.example.demo.supply.Product.ProductService;
|
||||
import com.example.demo.supply.Supplier.Supplier;
|
||||
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.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@ -30,8 +26,8 @@ public class OrderService {
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public Orders addOrder(Long supplierId){
|
||||
final Orders order = new Orders(new Date(System.currentTimeMillis()));
|
||||
public _Order addOrder(Long supplierId){
|
||||
final _Order order = new _Order(new Date(System.currentTimeMillis()));
|
||||
order.setSupplier(supplierService.findSupplier(supplierId));
|
||||
return orderRepository.save(order);
|
||||
}
|
||||
@ -44,40 +40,33 @@ public class OrderService {
|
||||
// }
|
||||
|
||||
@Transactional
|
||||
public Orders addProduct(Long id, Long productId) {
|
||||
final Orders currentOrder = findOrder(id);
|
||||
public _Order addProduct(Long id, Long productId) {
|
||||
final _Order currentOrder = findOrder(id);
|
||||
currentOrder.addProduct(productService.findProduct(productId));
|
||||
return orderRepository.save(currentOrder);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public Orders deleteProduct(Long id, Long productId) {
|
||||
final Orders currentOrder = findOrder(id);
|
||||
public _Order removeProduct(Long id, Long productId) {
|
||||
final _Order currentOrder = findOrder(id);
|
||||
currentOrder.addProduct(productService.findProduct(productId));
|
||||
return orderRepository.save(currentOrder);
|
||||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
public Orders findOrder(Long id) {
|
||||
final Optional<Orders> order = orderRepository.findById(id);
|
||||
public _Order findOrder(Long id) {
|
||||
final Optional<_Order> order = orderRepository.findById(id);
|
||||
return order.orElseThrow(() -> new OrderNotFoundException(id));
|
||||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
public List<Orders> findAllOrders() {
|
||||
public List<_Order> findAllOrders() {
|
||||
return orderRepository.findAll();
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public Orders updateOrder(Long id, Long supplierId) {
|
||||
final Orders currentOrder = findOrder(id);
|
||||
currentOrder.setSupplier(supplierService.findSupplier(supplierId));
|
||||
return orderRepository.save(currentOrder);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public Orders deleteOrder(Long id) {
|
||||
final Orders currentOrder = findOrder(id);
|
||||
public _Order deleteOrder(Long id) {
|
||||
final _Order currentOrder = findOrder(id);
|
||||
orderRepository.delete(currentOrder);
|
||||
return currentOrder;
|
||||
}
|
||||
|
@ -12,12 +12,12 @@ import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
@Entity
|
||||
public class Orders {
|
||||
public class _Order {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||
private Long id;
|
||||
|
||||
@Column
|
||||
@Column(nullable = false)
|
||||
@Temporal(TemporalType.DATE)
|
||||
private Date dateOfOrder;
|
||||
|
||||
@ -36,12 +36,12 @@ public class Orders {
|
||||
public Long getId(){
|
||||
return id;
|
||||
}
|
||||
public Orders(Date dateOfOrder) {
|
||||
public _Order(Date dateOfOrder) {
|
||||
this.dateOfOrder = dateOfOrder;
|
||||
products = new ArrayList<>();
|
||||
}
|
||||
|
||||
public Orders() {
|
||||
public _Order() {
|
||||
}
|
||||
|
||||
public Date getDateOfOrder() {
|
||||
@ -81,7 +81,7 @@ public class Orders {
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
Orders order = (Orders) o;
|
||||
_Order order = (_Order) o;
|
||||
if(!Objects.equals(id, order.id)) return false;
|
||||
|
||||
if(!Objects.equals(dateOfOrder.toString(), order.dateOfOrder.toString())) return false;
|
@ -1,8 +1,7 @@
|
||||
package com.example.demo.supply.Product;
|
||||
|
||||
import com.example.demo.supply.Order.Orders;
|
||||
import com.example.demo.supply.Order._Order;
|
||||
import jakarta.persistence.*;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -21,7 +20,7 @@ public class Product {
|
||||
@Column(nullable = false)
|
||||
private double cost;
|
||||
@ManyToMany(fetch = FetchType.EAGER, mappedBy = "products")
|
||||
private List<Orders> orders;
|
||||
private List<_Order> orders;
|
||||
|
||||
public Product(){}
|
||||
|
||||
@ -47,11 +46,11 @@ public class Product {
|
||||
this.cost = cost;
|
||||
}
|
||||
|
||||
public List<Orders> getOrders() {
|
||||
public List<_Order> getOrders() {
|
||||
return orders;
|
||||
}
|
||||
|
||||
public void setOrders(List<Orders> orders) {
|
||||
public void setOrders(List<_Order> orders) {
|
||||
this.orders = orders;
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
package com.example.demo.supply.Product;
|
||||
|
||||
import com.example.demo.supply.Order.Orders;
|
||||
import com.example.demo.supply.Order._Order;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -8,7 +8,7 @@ public class ProductDto {
|
||||
private long id;
|
||||
private String name;
|
||||
private double cost;
|
||||
private List<Orders> orders;
|
||||
private List<_Order> orders;
|
||||
|
||||
public ProductDto(Product product) {
|
||||
this.id = product.getId();
|
||||
@ -26,7 +26,7 @@ public class ProductDto {
|
||||
public double getCost() {
|
||||
return cost;
|
||||
}
|
||||
public List<Orders> getOrders() {
|
||||
public List<_Order> getOrders() {
|
||||
return orders;
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.example.demo.supply.Supplier;
|
||||
|
||||
import com.example.demo.supply.Order.Orders;
|
||||
import com.example.demo.supply.Order._Order;
|
||||
import com.example.demo.supply.Product.Product;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import jakarta.persistence.*;
|
||||
|
||||
@ -21,7 +22,7 @@ public class Supplier {
|
||||
|
||||
@JsonIgnore
|
||||
@OneToMany(fetch = FetchType.EAGER, mappedBy = "supplier", cascade = CascadeType.REMOVE)
|
||||
private List<Orders> orders;
|
||||
private List<_Order> orders;
|
||||
|
||||
public Supplier(){}
|
||||
|
||||
@ -48,11 +49,11 @@ public class Supplier {
|
||||
this.license = license;
|
||||
}
|
||||
|
||||
public List<Orders> getOrders() {
|
||||
public List<_Order> getOrders() {
|
||||
return orders;
|
||||
}
|
||||
|
||||
public void setOrders(List<Orders> orders) {
|
||||
public void setOrders(List<_Order> orders) {
|
||||
this.orders = orders;
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
package com.example.demo.supply.Supplier;
|
||||
|
||||
import com.example.demo.supply.Order.Orders;
|
||||
import com.example.demo.supply.Order._Order;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -8,7 +8,7 @@ public class SupplierDto {
|
||||
private Long id;
|
||||
private String name;
|
||||
private int license;
|
||||
private List<Orders> orders;
|
||||
private List<_Order> orders;
|
||||
|
||||
public SupplierDto(Supplier supplier){
|
||||
this.id = supplier.getId();
|
||||
@ -24,7 +24,7 @@ public class SupplierDto {
|
||||
public int getLicense() {
|
||||
return license;
|
||||
}
|
||||
public List<Orders> getOrders() {
|
||||
public List<_Order> getOrders() {
|
||||
return orders;
|
||||
}
|
||||
}
|
||||
|
@ -1,19 +1,7 @@
|
||||
package com.example.demo;
|
||||
|
||||
import com.example.demo.supply.Order.Orders;
|
||||
import com.example.demo.supply.Product.Product;
|
||||
import com.example.demo.supply.Product.ProductService;
|
||||
import com.example.demo.supply.Supplier.Supplier;
|
||||
import com.example.demo.supply.Order.OrderService;
|
||||
import com.example.demo.supply.Supplier.SupplierService;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@SpringBootTest
|
||||
public class Tests {
|
||||
}
|
@ -1,7 +1,8 @@
|
||||
import { BrowserRouter, Route, Routes} from "react-router-dom";
|
||||
import CatalogProducts from "./Pages/CatalogProducts";
|
||||
import CatalogSuppliers from "./Pages/CatalogSuppliers";
|
||||
import OrderPage from "./Pages/OrderPage";
|
||||
import OrderPage from "./Pages/OrdersPage";
|
||||
import CreateOrderPage from "./Pages/CreateOrderPage";
|
||||
import Header from "./general/Header";
|
||||
|
||||
function App() {
|
||||
@ -14,6 +15,7 @@ function App() {
|
||||
<Route path="/products" Component={CatalogProducts} />
|
||||
<Route path="/suppliers" Component={CatalogSuppliers} />
|
||||
<Route path="/orders" Component={OrderPage} />
|
||||
<Route path="/createOrder" Component={CreateOrderPage} />
|
||||
</Routes>
|
||||
|
||||
</BrowserRouter>
|
||||
|
131
front/src/Pages/CreateOrderPage.jsx
Normal file
131
front/src/Pages/CreateOrderPage.jsx
Normal file
@ -0,0 +1,131 @@
|
||||
import { React, useState, useEffect } from "react";
|
||||
import Supplier from "../models/Supplier";
|
||||
import DataService from "../DataService";
|
||||
import Order from "../models/Order";
|
||||
import Product from "../models/Product";
|
||||
import Table from "../general/Table";
|
||||
import Modal from "../general/Modal";
|
||||
|
||||
export default function CreateOrderPage(props){
|
||||
const url = 'order/'
|
||||
const supplierUrl = 'supplier/'
|
||||
const productUrl = 'product/'
|
||||
|
||||
const headers = [
|
||||
{ name: 'name', label: 'Продукт' },
|
||||
{ name: 'cost', label: 'Цена' }
|
||||
];
|
||||
|
||||
const transformer = (data) => new Order(data)
|
||||
const transformerSupplier = (data) => new Supplier(data)
|
||||
const transformerProduct = (data) => new Product(data)
|
||||
|
||||
const [suppliers, setSuppliers] = useState([])
|
||||
const [products, setProducts] = useState([])
|
||||
|
||||
const [productsOrder, setProductsOrder] = useState([])
|
||||
|
||||
const [modalHeader, setModalHeader] = useState('')
|
||||
const [modalConfirm, setModalConfirm] = useState('')
|
||||
const [modalVisible, setModalVisible] = useState(false)
|
||||
|
||||
useEffect(() => {
|
||||
loadItems()
|
||||
//eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, []);
|
||||
|
||||
const loadItems = () => {
|
||||
// DataService.getOrders(url).then(data => {
|
||||
// console.log(data)
|
||||
// setOrders([])
|
||||
// data.map(order => {
|
||||
// setOrders(prevState => [...prevState, new Order(order)])
|
||||
// })
|
||||
// })
|
||||
|
||||
DataService.readAll(supplierUrl, transformerSupplier).then(data => setSuppliers(data))
|
||||
DataService.readAll(productUrl, transformerProduct).then(data => setProducts(data))
|
||||
}
|
||||
|
||||
const saveItems = () => {
|
||||
console.log("saveItems")
|
||||
|
||||
}
|
||||
|
||||
const handleFormChange = (event) => {
|
||||
//console.log([event.target.id].event.target.value)
|
||||
// console.log(currOrder)
|
||||
// setData({ ...data, [event.target.id]: event.target.value })
|
||||
// console.log(data)
|
||||
}
|
||||
|
||||
const addProduct = () => {
|
||||
setModalHeader('Добавление продукта');
|
||||
setModalConfirm('Добавить');
|
||||
setModalVisible(true);
|
||||
}
|
||||
|
||||
const hideModal = () => setModalVisible(false)
|
||||
const modalDone = () => saveItems()
|
||||
const ds = () => console.log("")
|
||||
|
||||
return(
|
||||
<div className="container">
|
||||
<div className="row">
|
||||
<h1 className="display-6">Создание заказа</h1>
|
||||
</div>
|
||||
|
||||
<div className="row gx-5">
|
||||
<div className="btn-group" role="group" aria-label="Basic mixed styles example">
|
||||
<button type="button" className="btn btn-success">Создать</button>
|
||||
<button type="button" className="btn btn-danger">Отмена</button>
|
||||
</div>
|
||||
</div>
|
||||
<br></br>
|
||||
<div className="mb-3">
|
||||
<p className="h4" htmlFor="supplierId">Поставщик</p>
|
||||
<select id="supplierId" className="form-select " required
|
||||
onChange={handleFormChange}>
|
||||
<option disabled value="">Укажите поставщика</option>
|
||||
{
|
||||
suppliers.map(supplier =>
|
||||
<option key={supplier.id} value={supplier.id}>{supplier.name}</option>
|
||||
)
|
||||
}
|
||||
</select>
|
||||
</div>
|
||||
<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>
|
||||
</div>
|
||||
|
||||
<Table
|
||||
headers={headers}
|
||||
items={productsOrder}
|
||||
selectable={true}
|
||||
onClick={ds}
|
||||
onDblClick={ds}/>
|
||||
|
||||
<Modal
|
||||
header={modalHeader}
|
||||
confirm={modalConfirm}
|
||||
visible={modalVisible}
|
||||
onHide={hideModal}
|
||||
onDone={modalDone}>
|
||||
<div className="mb-3">
|
||||
<p className="h4" htmlFor="product">Продукт</p>
|
||||
<select id="product" className="form-select " required
|
||||
onChange={handleFormChange}>
|
||||
<option disabled value="">Укажите продукт</option>
|
||||
{
|
||||
products.map(product =>
|
||||
<option key={product.id} value={product.id}>{product.name}</option>
|
||||
)
|
||||
}
|
||||
</select>
|
||||
</div>
|
||||
</Modal>
|
||||
</div>
|
||||
)
|
||||
}
|
@ -1,3 +1,4 @@
|
||||
import { Link } from 'react-router-dom';
|
||||
import { React, useState, useEffect } from "react";
|
||||
import Table from "../general/Table";
|
||||
import ToolBar from "../general/ToolBar";
|
||||
@ -92,9 +93,9 @@ export default function OrderPage(){
|
||||
}
|
||||
|
||||
const handleFormChange = (event) => {
|
||||
console.log(currOrder)
|
||||
setData({ ...data, [event.target.id]: event.target.value })
|
||||
console.log(data)
|
||||
// console.log(currOrder)
|
||||
// setData({ ...data, [event.target.id]: event.target.value })
|
||||
// console.log(data)
|
||||
}
|
||||
|
||||
|
||||
@ -129,7 +130,7 @@ export default function OrderPage(){
|
||||
visible={modalVisible}
|
||||
onHide={hideModal}
|
||||
onDone={modalDone}>
|
||||
<div className="mb-3">
|
||||
{/* <div className="mb-3">
|
||||
<label htmlFor="supplierId" className="form-label">Поставщик</label>
|
||||
<select id="supplierId" className="form-select" required
|
||||
value={currOrder.supplierId} onChange={handleFormChange}>
|
||||
@ -140,9 +141,9 @@ export default function OrderPage(){
|
||||
)
|
||||
}
|
||||
</select>
|
||||
</div>
|
||||
</div> */}
|
||||
|
||||
<div className="mb-3">
|
||||
{/* <div className="mb-3">
|
||||
<label htmlFor="product" className="form-label">Поставщик</label>
|
||||
<select id="product" className="form-select" required
|
||||
onChange={handleFormChange}>
|
||||
@ -153,7 +154,7 @@ export default function OrderPage(){
|
||||
)
|
||||
}
|
||||
</select>
|
||||
</div>
|
||||
</div> */}
|
||||
</Modal>
|
||||
|
||||
<Modal
|
||||
@ -162,7 +163,7 @@ export default function OrderPage(){
|
||||
visible={addProdVisible}
|
||||
onHide={hideModal}
|
||||
onDone={modalDone}>
|
||||
<div className="mb-3">
|
||||
{/* <div className="mb-3">
|
||||
<label htmlFor="product" className="form-label">Поставщик</label>
|
||||
<select id="product" className="form-select" required
|
||||
value={products} onChange={handleFormChange}>
|
||||
@ -173,7 +174,7 @@ export default function OrderPage(){
|
||||
)
|
||||
}
|
||||
</select>
|
||||
</div>
|
||||
</div> */}
|
||||
</Modal>
|
||||
</>
|
||||
)
|
20
front/src/general/CastomSelect.jsx
Normal file
20
front/src/general/CastomSelect.jsx
Normal file
@ -0,0 +1,20 @@
|
||||
|
||||
export default function CastomSelect(props){
|
||||
|
||||
const handleFormChange = () => console.log("efhekjf")
|
||||
|
||||
return(
|
||||
<div className="mb-3">
|
||||
<label htmlFor="castomSelect" className="form-label">{props.header}</label>
|
||||
<select id="castomSelect" className="form-select" required
|
||||
value="" onChange={handleFormChange}>
|
||||
<option disabled value="">{props.description}</option>
|
||||
{
|
||||
props.items.map(item =>
|
||||
<option key={item.id} value={item.id}>{item.name}</option>
|
||||
)
|
||||
}
|
||||
</select>
|
||||
</div>
|
||||
)
|
||||
}
|
@ -16,7 +16,6 @@ export default function Header() {
|
||||
<Link className="nav-link" to="/products">
|
||||
Продукты
|
||||
</Link>
|
||||
|
||||
</li>
|
||||
<li className="nav-item">
|
||||
<Link className="nav-link" to="/suppliers">
|
||||
|
@ -1,3 +1,4 @@
|
||||
import { Link } from 'react-router-dom';
|
||||
import React from "react";
|
||||
import styles from './Toolbar.module.css';
|
||||
|
||||
@ -12,24 +13,23 @@ function ToolBar(props) {
|
||||
|
||||
return (
|
||||
<div className="btn-group mt-2" role="group">
|
||||
<button type="button" className={`btn btn-success ${styles.btn}`} onClick={add}>
|
||||
<button type="button" className={`btn btn-success ${styles.btn}`} onClick={add}
|
||||
style={{ display: props.addsVisible ? 'none' : 'block' }}>
|
||||
Добавить
|
||||
</button>
|
||||
<button type="button" className={`btn btn-warning ${styles.btn}`} onClick={edit} >
|
||||
<Link to="/createOrder">
|
||||
<button type="button" className={`btn btn-success ${styles.btn}`} onClick={add}
|
||||
style={{ display: props.addsVisible ? 'block' : 'none' }}>
|
||||
Добавить
|
||||
</button>
|
||||
</Link>
|
||||
<button type="button" className={`btn btn-warning ${styles.btn}`} onClick={edit}
|
||||
style={{ display: props.addsVisible ? 'none' : 'block' }}>
|
||||
Изменить
|
||||
</button >
|
||||
<button type="button" className={`btn btn-danger ${styles.btn}`} onClick={remove}>
|
||||
Удалить
|
||||
</button >
|
||||
|
||||
<button type="button" className={`btn btn-success ${styles.btn}`} onClick={addProduct}
|
||||
style={{ display: props.addsVisible ? 'block' : 'none' }}>
|
||||
Добавить продукт
|
||||
</button>
|
||||
<button type="button" className={`btn btn-danger ${styles.btn}`} onClick={removeProduct}
|
||||
style={{ display: props.addsVisible ? 'block' : 'none' }}>
|
||||
Удалить продукт
|
||||
</button >
|
||||
</div >
|
||||
|
||||
);
|
||||
|
Loading…
x
Reference in New Issue
Block a user