Commit 8e539b3d authored by Samuel Dudík's avatar Samuel Dudík
Browse files

Add alerts on checkout

parent 537e93d1
Pipeline #141067 passed with stages
in 2 minutes and 45 seconds
......@@ -16,6 +16,7 @@ import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.server.ResponseStatusException;
import org.springframework.web.servlet.ModelAndView;
import java.math.BigDecimal;
......@@ -24,6 +25,8 @@ import java.util.HashSet;
import java.util.Map;
import java.util.stream.Collectors;
import static org.springframework.http.HttpStatus.GONE;
@Controller
@RequestMapping("/cart")
public class CartController extends ControllerBase {
......@@ -103,7 +106,7 @@ public class CartController extends ControllerBase {
}
if (bottle.getStock() < entry.getValue())
return "Fail";
throw new ResponseStatusException(GONE, "Not enough products on stock.");
}
var order = new OrderDto();
......
......@@ -24,8 +24,14 @@ function setCartAmount(itemId, count) {
function checkout() {
return fetch(`${getUrlPrefix()}cart/checkout`,
{method: 'POST'}).then(() => {
window.location.href = `${getUrlPrefix()}myorder`;
{method: 'POST'}).then((res) => {
if (res.status == 410) {
document.getElementById("failure-alert").style.display = "block";
document.getElementById("success-alert").style.display = "none";
} else {
document.getElementById("success-alert").style.display = "block";
document.getElementById("failure-alert").style.display = "none";
}
});
}
......
......@@ -10,6 +10,19 @@
<div class="container px-4 px-lg-5">
<main role="main" class="pb-3">
<h4>Cart contents:</h4>
<div style="display: none;" id="success-alert">
<div class="alert alert-success mt-2" role="alert">
The order was sent successfully!
</div>
</div>
<div style="display: none;" id="failure-alert">
<div class="alert alert-danger mt-2" role="alert">
Not enough products on stock!
</div>
</div>
<table class="table">
<thead>
<th>Product Name</th>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment