hz
This commit is contained in:
parent
77ce0752c1
commit
cfe166c85a
BIN
data.mv.db
Normal file
BIN
data.mv.db
Normal file
Binary file not shown.
2898
front/package-lock.json
generated
Normal file
2898
front/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -33,13 +33,22 @@
|
||||
<div class="d-grid col-sm-6">
|
||||
<button id="removeBtn" class="btn btn-danger">Remove</button>
|
||||
</div>
|
||||
<div class="d-grid col-sm-6">
|
||||
<div class="d-grid col-sm-6 mx-auto">
|
||||
<button type="submit" class="btn btn-success">Add order</button>
|
||||
</div>
|
||||
<!--<div class="d-grid col-sm-6">
|
||||
<button id="relateBtn" class="btn btn-primary">Relate</button>
|
||||
</div>-->
|
||||
</div>
|
||||
<div class="row mt-3">
|
||||
<div class="col-sm-6">
|
||||
<label for="ticket" class="form-label">ticket id</label>
|
||||
<input type="text" class="form-control" id="ticket" required>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row mt-3">
|
||||
<div class="d-grid col-sm-6 mx-auto">
|
||||
<button type="submit" class="btn btn-success">Add empty order</button>
|
||||
<div class="d-grid col-sm-6">
|
||||
<button id="ticketBtn" class="btn btn-danger">Add ticket</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
@ -12,7 +12,7 @@ window.addEventListener('DOMContentLoaded', function () {
|
||||
table.innerHTML = "";
|
||||
const response = await fetch(host + "/order");
|
||||
const data = await response.json();
|
||||
/*data.forEach(order => {
|
||||
data.forEach(order => {
|
||||
let temp = "<select>";
|
||||
order.tickets.forEach(ticket => {
|
||||
temp += `<option>${ticket.name + " " + ticket.price + " " + ticket.timestamp}</option>`
|
||||
@ -24,9 +24,9 @@ window.addEventListener('DOMContentLoaded', function () {
|
||||
<td>${order.dateOfPurchase}</td>
|
||||
<td>${temp}</td>
|
||||
</tr>`;
|
||||
})*/
|
||||
})
|
||||
}
|
||||
async function create() {
|
||||
async function create(customer) {
|
||||
const requestParams = {
|
||||
method: "POST",
|
||||
headers: {
|
||||
@ -34,7 +34,7 @@ window.addEventListener('DOMContentLoaded', function () {
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
};
|
||||
const response = await fetch(host + `/order/post?post=`, requestParams);
|
||||
const response = await fetch(host + `/order?customer=${customer}`, requestParams);
|
||||
return await response.json();
|
||||
}
|
||||
async function remove(id) {
|
||||
@ -57,7 +57,7 @@ window.addEventListener('DOMContentLoaded', function () {
|
||||
|
||||
form.addEventListener("submit", function (event) {
|
||||
event.preventDefault();
|
||||
create().then(() => {
|
||||
create(customerInput.value).then(() => {
|
||||
getData();
|
||||
});
|
||||
});
|
||||
|
@ -41,12 +41,11 @@ public class OrderController {
|
||||
return new OrderDto(orderService.addCustomer(id, customer));
|
||||
}*/
|
||||
|
||||
/*@PutMapping("/{id}/updticket")
|
||||
@PutMapping("/{id}")
|
||||
public OrderDto updateOrder(@PathVariable Long id,
|
||||
@RequestParam("ticket") String ticket) {
|
||||
return new OrderDto(orderService.addTicket(id,
|
||||
ticketService.findTicket(Long.parseLong(ticket))));
|
||||
}*/
|
||||
@RequestParam("ticket") Long ticket) {
|
||||
return new OrderDto(orderService.addTicket(id, ticket));
|
||||
}
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
public OrderDto deleteOrder(@PathVariable Long id) {
|
||||
|
@ -55,12 +55,20 @@ public class OrderService {
|
||||
return customer.orElseThrow(() -> new CustomerNotFoundException(customer_id));
|
||||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
Ticket findTicket(Long ticket_id) {
|
||||
final Optional<Ticket> ticket = ticketRepository.findById(ticket_id);
|
||||
return ticket.orElseThrow(() -> new TicketNotFoundException(ticket_id));
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public Order addTicket(Long id, Ticket ticket) {
|
||||
public Order addTicket(Long id, Long ticket) {
|
||||
final Order currentOrder = findOrder(id);
|
||||
currentOrder.addTicket(ticket);
|
||||
ticket.setOrder(currentOrder);
|
||||
final Ticket currentTicket = findTicket(ticket);
|
||||
currentOrder.addTicket(currentTicket);
|
||||
currentTicket.setOrder(currentOrder);
|
||||
validatorUtil.validate(currentOrder);
|
||||
ticketRepository.save(currentTicket);
|
||||
return orderRepository.save(currentOrder);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user