This commit is contained in:
Overlordddd 2023-03-27 15:01:03 +04:00
parent 77ce0752c1
commit cfe166c85a
6 changed files with 2930 additions and 16 deletions

BIN
data.mv.db Normal file

Binary file not shown.

2898
front/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -33,13 +33,22 @@
<div class="d-grid col-sm-6"> <div class="d-grid col-sm-6">
<button id="removeBtn" class="btn btn-danger">Remove</button> <button id="removeBtn" class="btn btn-danger">Remove</button>
</div> </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> <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> </div>
<div class="row mt-3"> <div class="row mt-3">
<div class="d-grid col-sm-6 mx-auto"> <div class="d-grid col-sm-6">
<button type="submit" class="btn btn-success">Add empty order</button> <button id="ticketBtn" class="btn btn-danger">Add ticket</button>
</div> </div>
</div> </div>
</form> </form>

View File

@ -12,7 +12,7 @@ window.addEventListener('DOMContentLoaded', function () {
table.innerHTML = ""; table.innerHTML = "";
const response = await fetch(host + "/order"); const response = await fetch(host + "/order");
const data = await response.json(); const data = await response.json();
/*data.forEach(order => { data.forEach(order => {
let temp = "<select>"; let temp = "<select>";
order.tickets.forEach(ticket => { order.tickets.forEach(ticket => {
temp += `<option>${ticket.name + " " + ticket.price + " " + ticket.timestamp}</option>` temp += `<option>${ticket.name + " " + ticket.price + " " + ticket.timestamp}</option>`
@ -24,9 +24,9 @@ window.addEventListener('DOMContentLoaded', function () {
<td>${order.dateOfPurchase}</td> <td>${order.dateOfPurchase}</td>
<td>${temp}</td> <td>${temp}</td>
</tr>`; </tr>`;
})*/ })
} }
async function create() { async function create(customer) {
const requestParams = { const requestParams = {
method: "POST", method: "POST",
headers: { headers: {
@ -34,7 +34,7 @@ window.addEventListener('DOMContentLoaded', function () {
'Content-Type': 'application/json' '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(); return await response.json();
} }
async function remove(id) { async function remove(id) {
@ -57,7 +57,7 @@ window.addEventListener('DOMContentLoaded', function () {
form.addEventListener("submit", function (event) { form.addEventListener("submit", function (event) {
event.preventDefault(); event.preventDefault();
create().then(() => { create(customerInput.value).then(() => {
getData(); getData();
}); });
}); });

View File

@ -41,12 +41,11 @@ public class OrderController {
return new OrderDto(orderService.addCustomer(id, customer)); return new OrderDto(orderService.addCustomer(id, customer));
}*/ }*/
/*@PutMapping("/{id}/updticket") @PutMapping("/{id}")
public OrderDto updateOrder(@PathVariable Long id, public OrderDto updateOrder(@PathVariable Long id,
@RequestParam("ticket") String ticket) { @RequestParam("ticket") Long ticket) {
return new OrderDto(orderService.addTicket(id, return new OrderDto(orderService.addTicket(id, ticket));
ticketService.findTicket(Long.parseLong(ticket)))); }
}*/
@DeleteMapping("/{id}") @DeleteMapping("/{id}")
public OrderDto deleteOrder(@PathVariable Long id) { public OrderDto deleteOrder(@PathVariable Long id) {

View File

@ -55,12 +55,20 @@ public class OrderService {
return customer.orElseThrow(() -> new CustomerNotFoundException(customer_id)); 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 @Transactional
public Order addTicket(Long id, Ticket ticket) { public Order addTicket(Long id, Long ticket) {
final Order currentOrder = findOrder(id); final Order currentOrder = findOrder(id);
currentOrder.addTicket(ticket); final Ticket currentTicket = findTicket(ticket);
ticket.setOrder(currentOrder); currentOrder.addTicket(currentTicket);
currentTicket.setOrder(currentOrder);
validatorUtil.validate(currentOrder); validatorUtil.validate(currentOrder);
ticketRepository.save(currentTicket);
return orderRepository.save(currentOrder); return orderRepository.save(currentOrder);
} }