order add feature
This commit is contained in:
parent
5d8837809a
commit
30655dc5a8
@ -97,6 +97,7 @@ export default function Orders() {
|
|||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
console.error('Error:', error);
|
console.error('Error:', error);
|
||||||
|
alert('Не хватает билетов на сеанс')
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -139,6 +140,27 @@ export default function Orders() {
|
|||||||
.catch(e => { console.log('Error get orders') })
|
.catch(e => { console.log('Error get orders') })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function handleDeleteOrderSession(id, sessionId) {
|
||||||
|
console.info('Start delete session');
|
||||||
|
console.info(id+'-order, session-'+sessionId)
|
||||||
|
const requestParams = {
|
||||||
|
method: "PUT",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json"
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const requestUrl = `http://localhost:8080/order/${id}?session=${sessionId}`
|
||||||
|
const response = await fetch(requestUrl, requestParams)
|
||||||
|
await response.json()
|
||||||
|
.then((data) => {
|
||||||
|
console.info('End delete session')
|
||||||
|
setOrderSessions(data.sessions)
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
console.error('Error:', error);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
const Content = (
|
const Content = (
|
||||||
<>
|
<>
|
||||||
<select required className="form-select" name="customer" id="customer" value={customer.value} onChange={e => {
|
<select required className="form-select" name="customer" id="customer" value={customer.value} onChange={e => {
|
||||||
@ -211,6 +233,7 @@ export default function Orders() {
|
|||||||
<OrderSessionItem
|
<OrderSessionItem
|
||||||
item={item}
|
item={item}
|
||||||
key={parseInt(item.sessionId+''+item.orderId)}
|
key={parseInt(item.sessionId+''+item.orderId)}
|
||||||
|
removeFunc={(e) => handleDeleteOrderSession(e, currEditItem, item.sessionId)}
|
||||||
/>
|
/>
|
||||||
) : null}
|
) : null}
|
||||||
</tbody>
|
</tbody>
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import React, { useEffect, useState } from "react"
|
import React, { useEffect, useState } from "react"
|
||||||
import CinemaDto from "../models/CinemaDto";
|
import CinemaDto from "../models/CinemaDto";
|
||||||
import Service from "../services/Service";
|
import Service from "../services/Service";
|
||||||
|
import MyButton from "./MyButton";
|
||||||
|
|
||||||
export default function OrderSessionItem(props) {
|
export default function OrderSessionItem(props) {
|
||||||
const [item, setItem] = useState(new CinemaDto())
|
const [item, setItem] = useState(new CinemaDto())
|
||||||
@ -31,6 +32,7 @@ export default function OrderSessionItem(props) {
|
|||||||
<td>{item.cinema.name}</td>
|
<td>{item.cinema.name}</td>
|
||||||
<td>{date}</td>
|
<td>{date}</td>
|
||||||
<td>{props.item.count}</td>
|
<td>{props.item.count}</td>
|
||||||
|
<td><MyButton value={props} /></td>
|
||||||
</tr> : null}
|
</tr> : null}
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
|
@ -1,7 +1,14 @@
|
|||||||
package com.labwork1.app;
|
package com.labwork1.app;
|
||||||
|
|
||||||
|
import org.springframework.boot.web.server.ErrorPage;
|
||||||
|
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
|
||||||
|
import org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
||||||
|
import org.springframework.web.servlet.config.annotation.ViewControllerRegistration;
|
||||||
|
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
|
||||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||||
@Configuration
|
@Configuration
|
||||||
public class WebConfiguration implements WebMvcConfigurer {
|
public class WebConfiguration implements WebMvcConfigurer {
|
||||||
@ -9,4 +16,20 @@ public class WebConfiguration implements WebMvcConfigurer {
|
|||||||
public void addCorsMappings(CorsRegistry registry) {
|
public void addCorsMappings(CorsRegistry registry) {
|
||||||
registry.addMapping("/**").allowedMethods("*");
|
registry.addMapping("/**").allowedMethods("*");
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
|
public void addViewControllers(ViewControllerRegistry registry) {
|
||||||
|
ViewControllerRegistration registration = registry.addViewController("/notFound");
|
||||||
|
registration.setViewName("forward:/index.html");
|
||||||
|
registration.setStatusCode(HttpStatus.OK);
|
||||||
|
|
||||||
|
// Alternative way (404 error hits the console):
|
||||||
|
// > registry.addViewController("/notFound").setViewName("forward:/index.html");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public WebServerFactoryCustomizer<ConfigurableServletWebServerFactory> containerCustomizer() {
|
||||||
|
return container -> {
|
||||||
|
container.addErrorPages(new ErrorPage(HttpStatus.NOT_FOUND, "/notFound"));
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
@ -34,7 +34,9 @@ public class OrderController {
|
|||||||
@PutMapping("/{id}")
|
@PutMapping("/{id}")
|
||||||
public OrderDto updateOrder(@PathVariable Long id,
|
public OrderDto updateOrder(@PathVariable Long id,
|
||||||
@RequestParam("session") Long session,
|
@RequestParam("session") Long session,
|
||||||
@RequestParam("count") Integer count) {
|
@RequestParam(value = "count", required = false) Integer count) {
|
||||||
|
if (count == null)
|
||||||
|
return new OrderDto(orderService.deleteSessionInOrder(id, session, Integer.MAX_VALUE));
|
||||||
if (count > 0)
|
if (count > 0)
|
||||||
return new OrderDto(orderService.addSession(id, session, count));
|
return new OrderDto(orderService.addSession(id, session, count));
|
||||||
return new OrderDto(orderService.deleteSessionInOrder(id, session, -count));
|
return new OrderDto(orderService.deleteSessionInOrder(id, session, -count));
|
||||||
|
Loading…
Reference in New Issue
Block a user