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
f486f1ea
Commit
f486f1ea
authored
May 18, 2022
by
Ondřej Pavlica
Browse files
Cart fixes, grape delete cascade fixes
parent
42ed3f88
Pipeline
#140860
passed with stages
in 2 minutes and 58 seconds
Changes
5
Pipelines
1
Show whitespace changes
Inline
Side-by-side
winery/dao/src/main/java/cz/muni/fi/pa165/winery/persistence/entities/WineBottle.java
View file @
f486f1ea
...
...
@@ -76,4 +76,10 @@ public class WineBottle extends EntityBase{
*/
@OneToMany
(
mappedBy
=
"wineBottle"
,
fetch
=
FetchType
.
EAGER
,
cascade
=
CascadeType
.
REMOVE
)
private
Set
<
ProductReview
>
reviews
=
new
HashSet
<>();
/**
* The order items containing this wine bottle. Placed here just for cascading purposes.
*/
@OneToMany
(
mappedBy
=
"bottle"
,
fetch
=
FetchType
.
EAGER
,
cascade
=
CascadeType
.
REMOVE
)
private
Set
<
OrderItem
>
items
=
new
HashSet
<>();
}
winery/service/src/main/java/cz/muni/fi/pa165/winery/services/CartServiceImpl.java
View file @
f486f1ea
...
...
@@ -17,14 +17,16 @@ import java.util.stream.Collectors;
public
class
CartServiceImpl
implements
CartService
{
private
final
CookieService
cookieService
;
private
final
LoginContextService
loginContextService
;
public
CartServiceImpl
(
CookieService
cookieService
)
{
public
CartServiceImpl
(
CookieService
cookieService
,
LoginContextService
loginContextService
)
{
this
.
cookieService
=
cookieService
;
this
.
loginContextService
=
loginContextService
;
}
@Override
public
CartDto
loadFromCookie
()
{
var
cookieValue
=
cookieService
.
getCookie
(
"wineryCart"
);
var
cookieValue
=
cookieService
.
getCookie
(
getCartCookieName
()
);
if
(
cookieValue
==
null
)
{
return
new
CartDto
();
}
...
...
@@ -48,7 +50,7 @@ public class CartServiceImpl implements CartService {
catch
(
Exception
exception
)
{
json
=
null
;
}
cookieService
.
setCookie
(
"wineryCart"
,
json
);
cookieService
.
setCookie
(
getCartCookieName
()
,
json
);
}
@Override
...
...
@@ -66,4 +68,12 @@ public class CartServiceImpl implements CartService {
order
.
setItems
(
items
);
return
order
;
}
private
String
getCartCookieName
()
{
var
user
=
loginContextService
.
getCurrentUser
();
if
(
user
==
null
)
{
return
"wineryCart"
;
}
return
"wineryCart_"
+
user
.
getId
();
}
}
winery/service/src/main/java/cz/muni/fi/pa165/winery/services/LoginContextService.java
0 → 100644
View file @
f486f1ea
package
cz.muni.fi.pa165.winery.services
;
import
cz.muni.fi.pa165.winery.dto.user.UserDto
;
public
interface
LoginContextService
{
public
UserDto
getCurrentUser
();
}
winery/webapp/src/main/java/cz/muni/fi/pa165/winery/webapp/controllers/ControllerBase.java
View file @
f486f1ea
package
cz.muni.fi.pa165.winery.webapp.controllers
;
import
cz.muni.fi.pa165.winery.dto.user.UserDto
;
import
cz.muni.fi.pa165.winery.services.LoginContextService
;
import
cz.muni.fi.pa165.winery.services.user.UserService
;
import
cz.muni.fi.pa165.winery.webapp.models.ViewModelBase
;
import
cz.muni.fi.pa165.winery.services.CacheService
;
...
...
@@ -18,10 +19,7 @@ public class ControllerBase {
private
static
final
Pattern
CONTROLLER_NAME_REGEX
=
Pattern
.
compile
(
"^(?<name>\\w+?)(Controller)?$"
,
Pattern
.
CASE_INSENSITIVE
);
@Autowired
private
CacheService
cacheService
;
@Autowired
private
UserService
userService
;
private
LoginContextService
loginContextService
;
protected
ModelAndView
view
()
{
var
callingContext
=
getControllerAndAction
();
...
...
@@ -100,11 +98,7 @@ public class ControllerBase {
}
protected
UserDto
getCurrentUser
()
{
var
authentication
=
SecurityContextHolder
.
getContext
().
getAuthentication
();
var
dto
=
cacheService
.
cache
(
"_currentUser:"
+
authentication
.
getName
(),
()
->
userService
.
getByEmail
(
authentication
.
getName
()));
return
dto
;
return
loginContextService
.
getCurrentUser
();
}
private
void
initializeBindingMap
(
Map
<
String
,
Object
>
map
)
{
...
...
winery/webapp/src/main/java/cz/muni/fi/pa165/winery/webapp/services/LoginContextServiceImpl.java
0 → 100644
View file @
f486f1ea
package
cz.muni.fi.pa165.winery.webapp.services
;
import
cz.muni.fi.pa165.winery.dto.user.UserDto
;
import
cz.muni.fi.pa165.winery.services.CacheService
;
import
cz.muni.fi.pa165.winery.services.LoginContextService
;
import
cz.muni.fi.pa165.winery.services.user.UserService
;
import
org.springframework.security.core.context.SecurityContextHolder
;
import
org.springframework.stereotype.Service
;
@Service
public
class
LoginContextServiceImpl
implements
LoginContextService
{
private
final
CacheService
cacheService
;
private
final
UserService
userService
;
public
LoginContextServiceImpl
(
CacheService
cacheService
,
UserService
userService
)
{
this
.
cacheService
=
cacheService
;
this
.
userService
=
userService
;
}
@Override
public
UserDto
getCurrentUser
()
{
var
authentication
=
SecurityContextHolder
.
getContext
().
getAuthentication
();
var
dto
=
cacheService
.
cache
(
"_currentUser:"
+
authentication
.
getName
(),
()
->
userService
.
getByEmail
(
authentication
.
getName
()));
return
dto
;
}
}
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