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