нет json-ignore

This commit is contained in:
dasha 2023-04-17 18:24:00 +04:00
parent 1f4f290522
commit 3aff5cb712
7 changed files with 11 additions and 24 deletions

View File

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

View File

@ -5,7 +5,7 @@ export default function OrderItem(props) {
return (
<tr>
<td>{props.item.id}</td>
<td>{props.item.customer.login}</td>
<td>{props.item.customer}</td>
<td>{props.item.dateOfPurchase}</td>
<td><MyButton value={props} /></td>
</tr>

View File

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

View File

@ -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<Session> sessions;
@Lob
private byte[] image;

View File

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

View File

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

View File

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