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
6eaaf039
Commit
6eaaf039
authored
May 18, 2022
by
Ondřej Pavlica
Browse files
Fix checkout exception, add product names to cart listing
parent
f486f1ea
Pipeline
#140881
passed with stages
in 2 minutes and 22 seconds
Changes
7
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
winery/api/src/main/java/cz/muni/fi/pa165/winery/services/CartService.java
View file @
6eaaf039
...
...
@@ -6,5 +6,6 @@ import cz.muni.fi.pa165.winery.dto.order.OrderDto;
public
interface
CartService
{
CartDto
loadFromCookie
();
void
saveToCookie
(
CartDto
cart
);
void
clear
();
OrderDto
convertToOrder
(
CartDto
cart
,
long
userId
);
}
winery/dao/src/main/java/cz/muni/fi/pa165/winery/persistence/dao/DaoBaseImpl.java
View file @
6eaaf039
...
...
@@ -51,7 +51,7 @@ public class DaoBaseImpl<ENTITY extends EntityBase> implements DaoBase<ENTITY> {
public
ENTITY
get
(
long
id
,
boolean
useCachedResults
)
{
try
{
var
entity
=
entityManager
.
find
(
entityClass
,
id
);
if
(!
useCachedResults
)
{
if
(!
useCachedResults
&&
entity
!=
null
)
{
entityManager
.
refresh
(
entity
);
}
return
entity
;
...
...
winery/service/src/main/java/cz/muni/fi/pa165/winery/services/CartServiceImpl.java
View file @
6eaaf039
...
...
@@ -53,6 +53,11 @@ public class CartServiceImpl implements CartService {
cookieService
.
setCookie
(
getCartCookieName
(),
json
);
}
@Override
public
void
clear
()
{
cookieService
.
setCookie
(
getCartCookieName
(),
"{}"
);
}
@Override
public
OrderDto
convertToOrder
(
CartDto
cart
,
long
userId
)
{
var
order
=
new
OrderDto
();
...
...
winery/webapp/src/main/java/cz/muni/fi/pa165/winery/webapp/controllers/CartController.java
View file @
6eaaf039
...
...
@@ -106,19 +106,30 @@ public class CartController extends ControllerBase {
item
.
setBottleId
(
entry
.
getKey
());
item
.
setQuantity
(
new
BigDecimal
(
entry
.
getValue
()));
item
.
setOrderId
(
order
.
getId
());
item
.
setOrderId
(
order
.
getId
());
order
.
getItems
().
add
(
item
);
orderItemService
.
create
(
item
);
cart
.
remove
(
entry
.
getKey
());
var
bottle
=
wineBottleService
.
get
(
item
.
getBottleId
());
if
(
bottle
==
null
)
{
continue
;
}
bottle
.
setStock
(
bottle
.
getStock
()
-
item
.
getQuantity
().
intValue
());
orderItemService
.
create
(
item
);
wineBottleService
.
update
(
bottle
);
}
cartService
.
saveToCookie
(
c
ar
t
);
cartService
.
cle
ar
(
);
return
"Success"
;
}
@Override
protected
<
T
extends
ViewModelBase
>
void
initializeViewModel
(
T
viewModel
)
{
super
.
initializeViewModel
(
viewModel
);
if
(
viewModel
instanceof
CartListingViewModel
)
{
var
cartViewModel
=
(
CartListingViewModel
)
viewModel
;
var
productNames
=
wineBottleService
.
getAll
().
stream
().
collect
(
Collectors
.
toMap
(
x
->
x
.
getId
(),
x
->
x
.
getName
()));
cartViewModel
.
setProductNames
(
productNames
);
}
}
}
winery/webapp/src/main/java/cz/muni/fi/pa165/winery/webapp/controllers/ControllerBase.java
View file @
6eaaf039
...
...
@@ -112,7 +112,9 @@ public class ControllerBase {
private
Pair
<
String
,
String
>
getControllerAndAction
()
{
var
callerFrame
=
StackWalker
.
getInstance
(
StackWalker
.
Option
.
RETAIN_CLASS_REFERENCE
)
.
walk
(
s
->
s
.
filter
(
c
->
ControllerBase
.
class
.
isAssignableFrom
(
c
.
getDeclaringClass
())
&&
c
.
getDeclaringClass
()
!=
ControllerBase
.
class
)
s
.
filter
(
c
->
ControllerBase
.
class
.
isAssignableFrom
(
c
.
getDeclaringClass
())
&&
c
.
getDeclaringClass
()
!=
ControllerBase
.
class
&&
!
c
.
getMethodName
().
equals
(
"initializeViewModel"
))
.
findFirst
());
if
(!
callerFrame
.
isPresent
())
{
...
...
winery/webapp/src/main/java/cz/muni/fi/pa165/winery/webapp/models/cart/CartListingViewModel.java
View file @
6eaaf039
...
...
@@ -5,9 +5,11 @@ import lombok.Getter;
import
lombok.Setter
;
import
java.util.List
;
import
java.util.Map
;
@Getter
@Setter
public
class
CartListingViewModel
extends
ViewModelBase
{
private
List
<
CartItemViewModel
>
cart
;
private
Map
<
Long
,
String
>
productNames
;
}
winery/webapp/src/main/resources/templates/cart/test.html
View file @
6eaaf039
...
...
@@ -12,12 +12,12 @@
<h4>
Cart contents:
</h4>
<table
class=
"table"
>
<thead>
<th>
Item ID
</th>
<th>
Product Name
</th>
<th>
Count
</th>
</thead>
<tbody>
<tr
th:each=
"item : ${model.cart}"
>
<td
th:text=
"${item.productId}"
>
ID
</td>
<td
th:text=
"${
model.productNames[__${
item.productId}
__]}
"
>
ID
</td>
<td
th:text=
"${item.count}"
>
Count
</td>
</tr>
</tbody>
...
...
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