Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Samuel Dudík
PA165 Winery Management System
Commits
4cf88f82
Commit
4cf88f82
authored
May 18, 2022
by
Samuel Dudík
Browse files
Fix some cart issues
parent
6eaaf039
Pipeline
#140956
passed with stages
in 2 minutes and 35 seconds
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
winery/webapp/src/main/java/cz/muni/fi/pa165/winery/webapp/controllers/CartController.java
View file @
4cf88f82
...
...
@@ -63,6 +63,9 @@ public class CartController extends ControllerBase {
@PostMapping
(
"/add"
)
@ResponseBody
public
String
add
(
long
id
,
int
count
)
{
if
(
count
<
1
)
return
"Fail"
;
var
cart
=
cartService
.
loadFromCookie
();
cart
.
add
(
id
,
count
);
cartService
.
saveToCookie
(
cart
);
...
...
@@ -90,6 +93,19 @@ public class CartController extends ControllerBase {
@PostMapping
(
"/checkout"
)
@ResponseBody
public
String
add
()
{
var
cart
=
cartService
.
loadFromCookie
();
var
cartItems
=
cart
.
getCartItems
();
for
(
Map
.
Entry
<
Long
,
Integer
>
entry
:
cartItems
.
entrySet
())
{
var
bottle
=
wineBottleService
.
get
(
entry
.
getKey
());
if
(
bottle
==
null
)
{
continue
;
}
if
(
bottle
.
getStock
()
<
entry
.
getValue
())
return
"Fail"
;
}
var
order
=
new
OrderDto
();
order
.
setShipped
(
false
);
...
...
@@ -98,9 +114,6 @@ public class CartController extends ControllerBase {
orderService
.
create
(
order
);
var
cart
=
cartService
.
loadFromCookie
();
var
cartItems
=
cart
.
getCartItems
();
for
(
Map
.
Entry
<
Long
,
Integer
>
entry
:
cartItems
.
entrySet
())
{
var
item
=
new
OrderItemDto
();
item
.
setBottleId
(
entry
.
getKey
());
...
...
winery/webapp/src/main/resources/templates/cart/test.html
View file @
4cf88f82
...
...
@@ -14,11 +14,13 @@
<thead>
<th>
Product Name
</th>
<th>
Count
</th>
<th>
Delete
</th>
</thead>
<tbody>
<tr
th:each=
"item : ${model.cart}"
>
<td
th:text=
"${model.productNames[__${item.productId}__]}"
>
ID
</td>
<td
th:text=
"${item.count}"
>
Count
</td>
<td
th:text=
"${model.productNames[__${item.productId}__]}"
>
Product Name
</td>
<td><input
th:onchange=
"'setCartAmount(' + ${item.productId} + ', document.getElementById(\'quantity\').value)'"
type=
"number"
id=
"quantity"
name=
"quantity"
min=
"1"
th:value=
"${item.count}"
/></td>
<td><a
href=
"#"
th:onclick=
"'removeFromCart(' + ${item.productId} + ').then(x => refreshPage())'"
>
Delete
</a></td>
</tr>
</tbody>
</table>
...
...
winery/webapp/src/main/resources/templates/order/edit.html
View file @
4cf88f82
...
...
@@ -43,6 +43,7 @@
<h3>
Items
</h3>
<div
th:each=
"entry, stat : *{items}"
>
<span
th:text=
"*{wineNames[__${entry.bottleId}__]}"
/>
// TODO max = 5
<input
type=
"number"
id=
"quantity"
name=
"quantity"
min=
"1"
max=
"5"
th:field=
"*{quantities[__${entry.id}__]}"
>
</div>
<button
type=
"submit"
class=
"btn btn-primary"
>
Submit
</button>
...
...
winery/webapp/src/main/resources/templates/winebottle/detail.html
View file @
4cf88f82
...
...
@@ -42,7 +42,7 @@
</table>
<div
class=
"mb-2"
>
<input
id=
"itemCount"
type=
"number"
value=
"1"
/>
<input
id=
"itemCount"
type=
"number"
min=
"1"
value=
"1"
/>
<a
class=
"btn btn-primary btn-sm"
href=
"#"
th:onclick=
"'addToCart(' + ${model.id} + ', document.getElementById(\'itemCount\').value).then(x => document.getElementById(\'success-alert\').style.display = \'block\')'"
>
Add to cart
</a>
</div>
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment