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
2c27ce40
Commit
2c27ce40
authored
Apr 21, 2022
by
Jakub Balga
Browse files
Remaining service methods moved
parent
361d2db1
Pipeline
#130903
passed with stages
in 1 minute and 58 seconds
Changes
6
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
winery/dao/src/main/java/cz/muni/fi/pa165/winery/persistence/dao/wine/WineBottleDao.java
View file @
2c27ce40
package
cz.muni.fi.pa165.winery.persistence.dao.wine
;
import
cz.muni.fi.pa165.winery.persistence.dao.DaoBase
;
import
cz.muni.fi.pa165.winery.persistence.entities.ProductReview
;
import
cz.muni.fi.pa165.winery.persistence.entities.WineBottle
;
import
java.util.List
;
/**
* @author Michaela Korenkova
*/
public
interface
WineBottleDao
extends
DaoBase
<
WineBottle
>
{
List
<
WineBottle
>
getAll
(
double
minPrice
,
double
maxPrice
);
List
<
WineBottle
>
getAllOnStock
();
}
winery/dao/src/main/java/cz/muni/fi/pa165/winery/persistence/dao/wine/WineBottleDaoImpl.java
View file @
2c27ce40
package
cz.muni.fi.pa165.winery.persistence.dao.wine
;
import
cz.muni.fi.pa165.winery.exceptions.WineryDataAccessException
;
import
cz.muni.fi.pa165.winery.persistence.dao.DaoBaseImpl
;
import
cz.muni.fi.pa165.winery.persistence.entities.ProductReview
;
import
cz.muni.fi.pa165.winery.persistence.entities.WineBottle
;
import
org.springframework.stereotype.Repository
;
import
java.util.List
;
/**
* @author Michaela Korenkova
*/
...
...
@@ -12,4 +16,27 @@ public class WineBottleDaoImpl extends DaoBaseImpl<WineBottle> implements WineBo
public
WineBottleDaoImpl
()
{
super
(
WineBottle
.
class
);
}
public
List
<
WineBottle
>
getAll
(
double
minPrice
,
double
maxPrice
)
{
try
{
return
entityManager
.
createQuery
(
"select entity from "
+
WineBottle
.
class
.
getName
()
+
" entity "
+
"where entity.price >= "
+
minPrice
+
" and "
+
"entity.price <= "
+
maxPrice
,
WineBottle
.
class
)
.
getResultList
();
}
catch
(
Exception
ex
)
{
throw
new
WineryDataAccessException
(
ex
.
getMessage
(),
ex
);
}
}
public
List
<
WineBottle
>
getAllOnStock
()
{
try
{
return
entityManager
.
createQuery
(
"select entity from "
+
WineBottle
.
class
.
getName
()
+
" entity "
+
"where entity.stock > 0 "
,
WineBottle
.
class
)
.
getResultList
();
}
catch
(
Exception
ex
)
{
throw
new
WineryDataAccessException
(
ex
.
getMessage
(),
ex
);
}
}
}
\ No newline at end of file
winery/dao/src/main/java/cz/muni/fi/pa165/winery/persistence/dao/wine/WineTypeDao.java
View file @
2c27ce40
package
cz.muni.fi.pa165.winery.persistence.dao.wine
;
import
cz.muni.fi.pa165.winery.persistence.dao.DaoBase
;
import
cz.muni.fi.pa165.winery.persistence.entities.ProductReview
;
import
cz.muni.fi.pa165.winery.persistence.entities.WineType
;
import
java.util.List
;
/**
* @author Jakub Balga
*/
public
interface
WineTypeDao
extends
DaoBase
<
WineType
>
{
List
<
WineType
>
getAllByGrape
(
long
id
);
}
winery/dao/src/main/java/cz/muni/fi/pa165/winery/persistence/dao/wine/WineTypeDaoImpl.java
View file @
2c27ce40
package
cz.muni.fi.pa165.winery.persistence.dao.wine
;
import
cz.muni.fi.pa165.winery.exceptions.WineryDataAccessException
;
import
cz.muni.fi.pa165.winery.persistence.dao.DaoBaseImpl
;
import
cz.muni.fi.pa165.winery.persistence.entities.ProductReview
;
import
cz.muni.fi.pa165.winery.persistence.entities.WineType
;
import
org.springframework.stereotype.Repository
;
import
java.util.List
;
/**
* @author Jakub Balga
*/
...
...
@@ -14,5 +18,14 @@ public class WineTypeDaoImpl extends DaoBaseImpl<WineType> implements WineTypeDa
super
(
WineType
.
class
);
}
public
List
<
WineType
>
getAllByGrape
(
long
id
)
{
try
{
return
entityManager
.
createQuery
(
"select entity from "
+
WineType
.
class
.
getName
()
+
" entity "
+
"where entity.grape = "
+
id
,
WineType
.
class
)
.
getResultList
();
}
catch
(
Exception
ex
)
{
throw
new
WineryDataAccessException
(
ex
.
getMessage
(),
ex
);
}
}
}
winery/service/src/main/java/cz/muni/fi/pa165/winery/services/wine/WineBottleServiceImpl.java
View file @
2c27ce40
package
cz.muni.fi.pa165.winery.services.wine
;
import
cz.muni.fi.pa165.winery.dto.wine.WineBottleDto
;
import
cz.muni.fi.pa165.winery.persistence.dao.review.ProductReviewDao
;
import
cz.muni.fi.pa165.winery.persistence.dao.wine.WineBottleDao
;
import
cz.muni.fi.pa165.winery.persistence.entities.WineBottle
;
import
cz.muni.fi.pa165.winery.services.PersistenceServiceImpl
;
...
...
@@ -22,14 +23,13 @@ public class WineBottleServiceImpl extends PersistenceServiceImpl<WineBottleDto,
@Override
public
List
<
WineBottleDto
>
getAll
(
double
minPrice
,
double
maxPrice
)
{
return
getAll
().
stream
().
filter
(
e
->
e
.
getPrice
().
doubleValue
()
>=
minPrice
&&
e
.
getPrice
().
doubleValue
()
<=
maxPrice
)
.
collect
(
Collectors
.
toList
());
var
entities
=
((
WineBottleDao
)
getDao
()).
getAll
(
minPrice
,
maxPrice
);
return
entities
.
stream
().
map
(
this
::
mapToDto
).
collect
(
Collectors
.
toList
());
}
@Override
public
List
<
WineBottleDto
>
getAllOnStock
()
{
return
getAll
().
stream
().
filter
(
e
->
e
.
get
Stock
()
>
0
)
.
collect
(
Collectors
.
toList
());
var
entities
=
((
WineBottleDao
)
getDao
()).
getAllOn
Stock
()
;
return
entities
.
stream
().
map
(
this
::
mapToDto
)
.
collect
(
Collectors
.
toList
());
}
}
winery/service/src/main/java/cz/muni/fi/pa165/winery/services/wine/WineTypeServiceImpl.java
View file @
2c27ce40
...
...
@@ -26,25 +26,9 @@ public class WineTypeServiceImpl extends PersistenceServiceImpl<WineTypeDto, Win
this
.
wineBottleMapper
=
wineBottleMapper
;
}
@Override
protected
WineTypeDto
mapToDto
(
WineType
wineType
)
{
var
dto
=
super
.
mapToDto
(
wineType
);
dto
.
setWineBottles
(
wineType
.
getWineBottles
().
stream
()
.
map
(
x
->
wineBottleMapper
.
mapToDto
(
x
)).
collect
(
Collectors
.
toSet
()));
return
dto
;
}
@Override
protected
WineType
mapToEntity
(
WineTypeDto
record
)
{
var
entity
=
super
.
mapToEntity
(
record
);
entity
.
setWineBottles
(
record
.
getWineBottles
().
stream
()
.
map
(
x
->
wineBottleMapper
.
mapToEntity
(
x
)).
collect
(
Collectors
.
toSet
()));
return
entity
;
}
@Override
public
List
<
WineTypeDto
>
getAllByGrape
(
long
id
)
{
return
getAll
().
stream
().
filter
(
e
->
e
.
getGrape
().
getId
()
==
id
)
.
collect
(
Collectors
.
toList
());
var
entities
=
((
WineTypeDao
)
getDao
()).
getAllByGrape
(
id
)
;
return
entities
.
stream
().
map
(
this
::
mapToDto
)
.
collect
(
Collectors
.
toList
());
}
}
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