diff --git a/front/src/pages/Orders.jsx b/front/src/pages/Orders.jsx index 6aa4422..e83d407 100644 --- a/front/src/pages/Orders.jsx +++ b/front/src/pages/Orders.jsx @@ -7,7 +7,6 @@ import OrderSessionItem from './components/OrderSessionItem'; export default function Orders() { const [users, setUsers] = useState([]); - const [error, setError] = useState(false); const [modalTable, setModalTable] = useState(false); // хук для запоминания индекса элемента, вызвавшего модальное окно const [currEditItem, setCurrEditItem] = useState(0); @@ -20,7 +19,6 @@ export default function Orders() { const [orderSessions, setOrderSessions] = useState([]); useEffect(() => { - setError(false) getAll('customer').then((data) => setCustomer(data)) getAll('session').then((data) => setSession(data)) getAll('order').then((data) => setUsers(data)) @@ -36,12 +34,10 @@ export default function Orders() { function handleSubmit(e) { e.preventDefault(); if (customer.length <= 0) { - setError(true) throw 'Form not submit' } handleSubmitCreate(e) console.log('Form submit') - setError(false) setCustomer('') } @@ -92,7 +88,6 @@ export default function Orders() { const response = await fetch(requestUrl, requestParams) await response.json() .then((data) => { - console.log(data.sessions) setOrderSessions(data.sessions) console.info('End add session'); }) @@ -143,7 +138,6 @@ export default function Orders() { async function handleDeleteOrderSession(e, id, sessionId) { console.info('Start delete session'); - console.info(id+'-order, session-'+sessionId) const requestParams = { method: "PUT", headers: { diff --git a/front/src/pages/components/OrderItem.jsx b/front/src/pages/components/OrderItem.jsx index 4f08c0b..273715a 100644 --- a/front/src/pages/components/OrderItem.jsx +++ b/front/src/pages/components/OrderItem.jsx @@ -5,7 +5,7 @@ export default function OrderItem(props) { return ( {props.item.id} - {props.item.customer.login} + {props.item.customer} {props.item.dateOfPurchase} diff --git a/src/main/java/com/labwork1/app/student/controller/OrderDto.java b/src/main/java/com/labwork1/app/student/controller/OrderDto.java index 4dcbbb2..74727c0 100644 --- a/src/main/java/com/labwork1/app/student/controller/OrderDto.java +++ b/src/main/java/com/labwork1/app/student/controller/OrderDto.java @@ -10,7 +10,7 @@ import java.util.List; public class OrderDto { private long id; private Date dateOfPurchase; - private Customer customer; + private String customer; private List sessions; public OrderDto() { @@ -19,7 +19,7 @@ public class OrderDto { public OrderDto(Order order) { this.id = order.getId(); this.dateOfPurchase = order.getDateOfPurchase(); - this.customer = order.getCustomer(); + this.customer = order.getCustomer().getLogin(); if (order.getSessions() != null && order.getSessions().size() > 0) this.sessions = order.getSessions() .stream() @@ -35,7 +35,7 @@ public class OrderDto { return dateOfPurchase; } - public Customer getCustomer() { + public String getCustomer() { return customer; } diff --git a/src/main/java/com/labwork1/app/student/model/Cinema.java b/src/main/java/com/labwork1/app/student/model/Cinema.java index 1a45c0b..a6e3ae0 100644 --- a/src/main/java/com/labwork1/app/student/model/Cinema.java +++ b/src/main/java/com/labwork1/app/student/model/Cinema.java @@ -1,6 +1,5 @@ package com.labwork1.app.student.model; -import com.fasterxml.jackson.annotation.JsonIgnore; import com.labwork1.app.student.controller.CinemaDto; import jakarta.persistence.*; import jakarta.validation.constraints.NotBlank; @@ -17,7 +16,6 @@ public class Cinema { @Column private String name; @OneToMany(fetch = FetchType.EAGER, mappedBy = "cinema", cascade = CascadeType.REMOVE) - @JsonIgnore private List sessions; @Lob private byte[] image; diff --git a/src/main/java/com/labwork1/app/student/model/Order.java b/src/main/java/com/labwork1/app/student/model/Order.java index c33f811..3ed3ab4 100644 --- a/src/main/java/com/labwork1/app/student/model/Order.java +++ b/src/main/java/com/labwork1/app/student/model/Order.java @@ -1,6 +1,5 @@ package com.labwork1.app.student.model; -import com.fasterxml.jackson.annotation.JsonIgnore; import jakarta.persistence.*; import jakarta.validation.constraints.NotNull; @@ -20,7 +19,6 @@ public class Order { private Date dateOfPurchase; @ManyToOne(fetch = FetchType.EAGER) @JoinColumn(name = "customer_fk") - @JsonIgnore private Customer customer; @OneToMany(mappedBy = "order", fetch = FetchType.EAGER, cascade = { diff --git a/src/main/java/com/labwork1/app/student/model/OrderSession.java b/src/main/java/com/labwork1/app/student/model/OrderSession.java index b76afe6..24b7ef9 100644 --- a/src/main/java/com/labwork1/app/student/model/OrderSession.java +++ b/src/main/java/com/labwork1/app/student/model/OrderSession.java @@ -1,6 +1,5 @@ package com.labwork1.app.student.model; -import com.fasterxml.jackson.annotation.JsonIgnore; import jakarta.persistence.*; @Entity @@ -11,12 +10,10 @@ public class OrderSession { @ManyToOne @MapsId("sessionId") @JoinColumn(name = "session_id") - @JsonIgnore private Session session; @ManyToOne @MapsId("orderId") @JoinColumn(name = "order_id") - @JsonIgnore private Order order; @Column(name = "count") private Integer count; diff --git a/src/test/java/com/labwork1/app/JpaCustomerTests.java b/src/test/java/com/labwork1/app/JpaCustomerTests.java index 84ffdd4..28da02c 100644 --- a/src/test/java/com/labwork1/app/JpaCustomerTests.java +++ b/src/test/java/com/labwork1/app/JpaCustomerTests.java @@ -68,7 +68,7 @@ public class JpaCustomerTests { .addOrder(customerService.findCustomer(customer2.getId()).getId()); // у заказа 2 сеанса orderService.addSession(order2.getId(), session1.getId(), 2); - Assertions.assertEquals(sessionService.getCapacity(session1.getId()), 8); + Assertions.assertEquals(sessionService.getCapacity(session1.getId()), 2); orderService.addSession(order2.getId(), session2.getId(), 5); Assertions.assertEquals(sessionService.getCapacity(session2.getId()), 5); @@ -78,16 +78,16 @@ public class JpaCustomerTests { // у заказа 1 сеанс orderService.deleteSessionInOrder(order2.getId(), session2.getId(), 10); - Assertions.assertEquals(sessionService.getCapacity(session2.getId()), 10); + Assertions.assertEquals(sessionService.getCapacity(session2.getId()), 0); // заполнили всю 2 сессию orderService.addSession(order2.getId(), session2.getId(), 10); Assertions.assertEquals(sessionService.findAllSessions().size(), 2); orderService.deleteSessionInOrder(order2.getId(), session2.getId(), 4); - Assertions.assertEquals(sessionService.getCapacity(session2.getId()), 4); + Assertions.assertEquals(sessionService.getCapacity(session2.getId()), 6); orderService.deleteSessionInOrder(order2.getId(), session2.getId(), 6); - Assertions.assertEquals(sessionService.getCapacity(session2.getId()), 10); + Assertions.assertEquals(sessionService.getCapacity(session2.getId()), 0); Assertions.assertEquals(orderService.findOrder(order2.getId()).getSessions().size(), 1); Assertions.assertEquals(orderService.findOrder(order2.getId()).getSessions().get(0).getId().getSessionId(), session1.getId()); @@ -109,14 +109,14 @@ public class JpaCustomerTests { orderService.addSession(order3.getId(), session1.getId(), 8); // 2-ой покупатель удален // 0 заказов после его удаления - Assertions.assertEquals(sessionService.getCapacity(session2.getId()), 8); + Assertions.assertEquals(sessionService.getCapacity(session2.getId()), 2); customerService.deleteCustomer(customer2.getId()); Assertions.assertThrows(CustomerNotFoundException.class, () -> customerService.findCustomer(customer2.getId())); Assertions.assertThrows(OrderNotFoundException.class, () -> orderService.findOrder(order3.getId())); Assertions.assertEquals(orderService.findAllOrders().size(), 0); - Assertions.assertEquals(sessionService.getCapacity(session2.getId()), 10); - Assertions.assertEquals(sessionService.getCapacity(session3.getId()), 10); + Assertions.assertEquals(sessionService.getCapacity(session2.getId()), 0); + Assertions.assertEquals(sessionService.getCapacity(session3.getId()), 0); Assertions.assertEquals(cinemaService.findAllCinemas().size(), 2); Assertions.assertEquals(sessionService.findAllSessions().size(), 3);