Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Michal Čížek
flea-market-manager
Commits
fc4c1936
Commit
fc4c1936
authored
May 25, 2022
by
Lucia Lopuchova
Browse files
Delete some not used functions
parent
73c412f4
Changes
9
Show whitespace changes
Inline
Side-by-side
backend/flea-market-manager-controller/src/main/java/cz/fi/muni/pa165/flea/market/manager/controllers/StandController.java
View file @
fc4c1936
...
...
@@ -9,7 +9,6 @@ import cz.fi.muni.pa165.flea.market.manager.dto.stand.StandUserDTO;
import
cz.fi.muni.pa165.flea.market.manager.dto.standType.StandTypeDTO
;
import
cz.fi.muni.pa165.flea.market.manager.dto.user.UserDTO
;
import
cz.fi.muni.pa165.flea.market.manager.entity.Stand
;
import
cz.fi.muni.pa165.flea.market.manager.entity.StandType
;
import
cz.fi.muni.pa165.flea.market.manager.enums.ItemCategory
;
import
cz.fi.muni.pa165.flea.market.manager.service.StandService
;
import
io.swagger.v3.oas.annotations.tags.Tag
;
...
...
@@ -80,12 +79,6 @@ public class StandController {
return
stands
.
stream
().
map
(
standService:
:
constructDTOFromStand
).
collect
(
Collectors
.
toList
());
}
@GetMapping
(
value
=
"/list/category/{categoryId}"
)
public
List
<
StandDTO
>
listByItemCategory
(
@PathVariable
String
categoryId
)
{
List
<
Stand
>
stands
=
standService
.
findAllByItemCategory
(
categoryId
);
return
stands
.
stream
().
map
(
stand
->
mapper
.
map
(
stand
,
StandDTO
.
class
)).
collect
(
Collectors
.
toList
());
}
@GetMapping
(
value
=
"/{id}"
)
public
StandDTO
find
(
@PathVariable
(
"id"
)
String
id
)
{
Stand
stand
=
standService
.
findById
(
id
);
...
...
backend/flea-market-manager-persistence/src/main/java/cz/fi/muni/pa165/flea/market/manager/dao/StandDao.java
View file @
fc4c1936
...
...
@@ -32,14 +32,6 @@ public class StandDao extends DomainDaoImpl<Stand, QStand> {
.
list
(
qEntity
);
}
public
List
<
Stand
>
findAllByItemCategory
(
@NonNull
String
itemCategory
)
{
JPAQuery
query
=
new
JPAQuery
(
entityManager
);
return
query
.
from
(
qEntity
)
.
where
(
qEntity
.
itemCategories
.
contains
(
ItemCategory
.
valueOf
(
itemCategory
)))
.
list
(
qEntity
);
}
public
List
<
Stand
>
findAllByEventId
(
@NonNull
String
eventId
)
{
JPAQuery
query
=
new
JPAQuery
(
entityManager
);
return
query
...
...
@@ -48,22 +40,6 @@ public class StandDao extends DomainDaoImpl<Stand, QStand> {
.
list
(
qEntity
);
}
public
List
<
Stand
>
findAllInPriceRange
(
@NonNull
Long
fromStandPrice
,
Long
toStandPrice
)
{
JPAQuery
query
=
new
JPAQuery
(
entityManager
);
if
(
Objects
.
isNull
(
toStandPrice
))
{
return
query
.
from
(
qEntity
)
.
where
(
qEntity
.
standType
.
priceInCents
.
gt
(
fromStandPrice
))
.
list
(
qEntity
);
}
return
query
.
from
(
qEntity
)
.
where
(
qEntity
.
standType
.
priceInCents
.
between
(
fromStandPrice
,
toStandPrice
))
.
list
(
qEntity
);
}
public
List
<
Stand
>
findAllByStandType
(
@NonNull
String
standTypeId
)
{
JPAQuery
query
=
new
JPAQuery
(
entityManager
);
...
...
backend/flea-market-manager-persistence/src/main/java/cz/fi/muni/pa165/flea/market/manager/dao/StandTypeDao.java
View file @
fc4c1936
...
...
@@ -18,14 +18,6 @@ public class StandTypeDao extends DomainDaoImpl<StandType, QStandType> {
public
StandTypeDao
()
{
super
(
StandType
.
class
,
QStandType
.
standType
);
}
public
StandType
findByName
(
@NonNull
String
name
){
JPAQuery
query
=
new
JPAQuery
(
entityManager
);
return
query
.
from
(
qEntity
)
.
where
(
qEntity
.
name
.
eq
(
name
))
.
singleResult
(
qEntity
);
}
}
backend/flea-market-manager-persistence/src/test/java/cz/fi/muni/pa165/flea/market/manager/StandDaoTest.java
View file @
fc4c1936
...
...
@@ -231,35 +231,6 @@ class StandDaoTest {
SoftAssertions
.
assertSoftly
(
softAssertions
->
softAssertions
.
assertThat
(
sellerStands
).
isEqualTo
(
standDao
.
findAllBySellerId
(
exampleStandSellerId
)).
usingRecursiveComparison
());
}
@Test
@Transactional
public
void
findAllByItemCategory
()
{
initDatabase
();
Stand
exampleStand
=
generateRandomStand
();
entityManager
.
persist
(
exampleStand
);
String
exampleStandCategory
=
ItemCategory
.
FURNITURE
.
name
();
List
<
Stand
>
stands
=
jpaQuery
().
from
(
stand
).
where
(
stand
.
itemCategories
.
contains
(
ItemCategory
.
valueOf
(
exampleStandCategory
))).
list
(
stand
);
SoftAssertions
.
assertSoftly
(
softAssertions
->
softAssertions
.
assertThat
(
stands
).
isEqualTo
(
standDao
.
findAllByItemCategory
(
exampleStandCategory
)).
usingRecursiveComparison
());
}
@Test
@Transactional
public
void
findAllInPriceRange
()
{
initDatabase
();
Stand
exampleStand
=
generateRandomStand
();
entityManager
.
persist
(
exampleStand
);
Long
exampleStandPrice
=
exampleStand
.
getStandType
().
getPriceInCents
();
List
<
Stand
>
stands
=
jpaQuery
().
from
(
stand
).
where
(
stand
.
standType
.
priceInCents
.
between
(
exampleStandPrice
-
1
,
exampleStandPrice
+
1
)).
list
(
stand
);
SoftAssertions
.
assertSoftly
(
softAssertions
->
softAssertions
.
assertThat
(
stands
).
isEqualTo
(
standDao
.
findAllInPriceRange
(
exampleStandPrice
-
1
,
exampleStandPrice
+
1
)).
usingRecursiveComparison
());
}
@Test
@Transactional
public
void
findAllByStandType
()
{
...
...
backend/flea-market-manager-persistence/src/test/java/cz/fi/muni/pa165/flea/market/manager/StandTypeDaoTest.java
View file @
fc4c1936
...
...
@@ -140,23 +140,6 @@ class StandTypeDaoTest {
);
}
@Test
@Transactional
public
void
findByName
()
{
StandType
standType
=
generateRandomStandType
();
entityManager
.
persist
(
standType
);
StandType
foundStandType
=
standTypeDao
.
findByName
(
standType
.
getName
());
SoftAssertions
.
assertSoftly
(
softAssertions
->
softAssertions
.
assertThat
(
foundStandType
).
isEqualTo
(
standType
).
usingRecursiveComparison
());
}
@Test
@Transactional
public
void
findByNullName
(){
assertThrows
(
NullPointerException
.
class
,
()
->
standTypeDao
.
findByName
(
null
));
}
@Test
@Transactional
public
void
deleteNullArgument
()
{
...
...
backend/flea-market-manager-service/src/main/java/cz/fi/muni/pa165/flea/market/manager/service/StandService.java
View file @
fc4c1936
...
...
@@ -51,18 +51,6 @@ public class StandService extends DomainServiceImpl<Stand> {
}
}
public
List
<
Stand
>
findAllByItemCategory
(
@NonNull
String
itemCategory
)
{
if
(!
Arrays
.
toString
(
ItemCategory
.
values
()).
contains
(
itemCategory
))
{
throw
new
IllegalArgumentException
(
"Unknown item category"
);
}
try
{
return
dao
.
findAllByItemCategory
(
itemCategory
);
}
catch
(
Exception
e
)
{
throw
new
DaoException
(
e
.
getMessage
(),
e
);
}
}
public
List
<
Stand
>
findAllByEventId
(
@NonNull
String
eventId
)
{
try
{
return
dao
.
findAllByEventId
(
eventId
);
...
...
@@ -71,18 +59,6 @@ public class StandService extends DomainServiceImpl<Stand> {
}
}
public
List
<
Stand
>
findAllInPriceRange
(
@NonNull
Long
fromStandPrice
,
Long
toStandPrice
)
{
if
(
toStandPrice
!=
null
&&
toStandPrice
<
fromStandPrice
)
{
throw
new
IllegalArgumentException
(
"To price cannot be bigger than from price"
);
}
try
{
return
dao
.
findAllInPriceRange
(
fromStandPrice
,
toStandPrice
);
}
catch
(
Exception
e
)
{
throw
new
DaoException
(
e
.
getMessage
(),
e
);
}
}
public
Stand
constructStandFromDTO
(
@NonNull
StandCreateDTO
standCreateDTO
)
{
Stand
stand
=
new
Stand
();
...
...
backend/flea-market-manager-service/src/main/java/cz/fi/muni/pa165/flea/market/manager/service/StandTypeService.java
View file @
fc4c1936
...
...
@@ -25,14 +25,11 @@ import java.util.List;
@Transactional
public
class
StandTypeService
extends
DomainServiceImpl
<
StandType
>
{
private
final
StandTypeDao
standTypeDao
;
private
final
StandDao
standDao
;
@Autowired
public
StandTypeService
(
StandTypeDao
standTypeDao
,
StandDao
standDao
)
{
super
(
standTypeDao
);
this
.
standTypeDao
=
standTypeDao
;
this
.
standDao
=
standDao
;
}
...
...
@@ -55,14 +52,6 @@ public class StandTypeService extends DomainServiceImpl<StandType> {
super
.
delete
(
standType
);
}
public
StandType
findByName
(
@NonNull
String
name
)
{
try
{
return
standTypeDao
.
findByName
(
name
);
}
catch
(
Exception
e
){
throw
new
DaoException
(
e
.
getMessage
(),
e
);
}
}
public
StandType
constructStandTypeFromDTO
(
@NonNull
StandTypeCreateDTO
dto
)
{
StandType
standType
=
new
StandType
();
standType
.
setName
(
dto
.
getName
());
...
...
backend/flea-market-manager-service/src/test/java/cz/fi/muni/pa165/flea/market/manager/StandServiceTest.java
View file @
fc4c1936
...
...
@@ -204,83 +204,4 @@ public class StandServiceTest {
public
void
findByNullUserId
()
{
Assertions
.
assertThatThrownBy
(()
->
standService
.
findAllBySellerId
(
null
)).
isInstanceOf
(
NullPointerException
.
class
);
}
@Test
@Transactional
public
void
findAllByItemCategory
()
{
Stand
randomStand1
=
getRandomStand
(
"id1"
);
Stand
randomStand2
=
getRandomStand
(
"id2"
);
Set
<
ItemCategory
>
randomStandcategories
=
new
HashSet
<>();
randomStandcategories
.
add
(
ItemCategory
.
FURNITURE
);
randomStandcategories
.
add
(
ItemCategory
.
OTHER
);
randomStand2
.
setItemCategories
(
randomStandcategories
);
when
(
standDao
.
create
(
stand
)).
thenReturn
(
stand
);
when
(
standDao
.
create
(
randomStand1
)).
thenReturn
(
randomStand1
);
when
(
standDao
.
create
(
randomStand2
)).
thenReturn
(
randomStand2
);
when
(
standDao
.
findAllByItemCategory
(
any
())).
thenReturn
(
List
.
of
(
stand
,
randomStand1
));
standService
.
create
(
stand
);
standService
.
create
(
randomStand1
);
standService
.
create
(
randomStand2
);
List
<
Stand
>
foundStands
=
standService
.
findAllByItemCategory
(
ItemCategory
.
OTHER
.
name
());
SoftAssertions
.
assertSoftly
(
softAssertions
->
{
softAssertions
.
assertThat
(
foundStands
.
size
()).
isEqualTo
(
2
);
softAssertions
.
assertThat
(
foundStands
).
isEqualTo
(
List
.
of
(
stand
,
randomStand1
)).
usingRecursiveComparison
();
});
}
@Test
@Transactional
public
void
findAllByNullItemCategory
()
{
Assertions
.
assertThatThrownBy
(()
->
standService
.
findAllByItemCategory
(
null
)).
isInstanceOf
(
NullPointerException
.
class
);
}
@Test
@Transactional
public
void
findAllByNonExistingItemCategory
()
{
Assertions
.
assertThatThrownBy
(()
->
standService
.
findAllByItemCategory
(
faker
.
witcher
().
character
())).
isInstanceOf
(
IllegalArgumentException
.
class
);
}
@Test
@Transactional
public
void
findAllInPriceRange
()
{
Long
from
=
100L
;
Long
to
=
200L
;
Stand
withPriceInRange
=
getRandomStand
(
"id1"
);
StandType
standType1
=
getRandomStandType
();
standType1
.
setPriceInCents
(
150L
);
withPriceInRange
.
setStandType
(
standType1
);
Stand
withPriceOutOfRange
=
getRandomStand
(
"id2"
);
StandType
standType2
=
getRandomStandType
();
standType1
.
setPriceInCents
(
99L
);
withPriceInRange
.
setStandType
(
standType2
);
when
(
standDao
.
findAllInPriceRange
(
from
,
to
)).
thenReturn
(
List
.
of
(
withPriceInRange
));
when
(
standDao
.
create
(
withPriceInRange
)).
thenReturn
(
withPriceInRange
);
when
(
standDao
.
create
(
withPriceOutOfRange
)).
thenReturn
(
withPriceOutOfRange
);
standService
.
create
(
withPriceInRange
);
standService
.
create
(
withPriceOutOfRange
);
List
<
Stand
>
standsInRange
=
standService
.
findAllInPriceRange
(
from
,
to
);
SoftAssertions
.
assertSoftly
(
softAssertions
->
{
softAssertions
.
assertThat
(
standsInRange
.
size
()).
isEqualTo
(
1
);
softAssertions
.
assertThat
(
standsInRange
.
get
(
0
)).
isEqualTo
(
withPriceInRange
).
usingRecursiveComparison
();
softAssertions
.
assertThat
(
standsInRange
).
doesNotContain
(
withPriceOutOfRange
);
});
}
@Test
@Transactional
public
void
findAllByInvalidPriceRange
()
{
Assertions
.
assertThatThrownBy
(()
->
standService
.
findAllInPriceRange
(
200L
,
100L
)).
isInstanceOf
(
IllegalArgumentException
.
class
);
}
}
backend/flea-market-manager-service/src/test/java/cz/fi/muni/pa165/flea/market/manager/StandTypeServiceTest.java
View file @
fc4c1936
...
...
@@ -138,24 +138,6 @@ public class StandTypeServiceTest {
assertThatThrownBy
(()
->
standTypeService
.
delete
(
testStandType
)).
isInstanceOf
(
IllegalArgumentException
.
class
);
}
@Test
@Transactional
public
void
findByName
(){
when
(
standTypeDao
.
findByName
(
testStandType
.
getName
())).
thenReturn
(
testStandType
);
when
(
standTypeDao
.
create
(
any
())).
thenReturn
(
testStandType
);
standTypeService
.
create
(
testStandType
);
StandType
foundStandType
=
standTypeService
.
findByName
(
testStandType
.
getName
());
SoftAssertions
.
assertSoftly
(
softAssertions
->
softAssertions
.
assertThat
(
foundStandType
).
isEqualTo
(
testStandType
).
usingRecursiveComparison
());
}
@Test
@Transactional
public
void
findByNullName
(){
assertThatThrownBy
(()
->
standTypeService
.
findByName
(
null
)).
isInstanceOf
(
NullPointerException
.
class
);
}
private
StandType
createStandTypeWithPrice
(
Long
price
)
{
StandType
location
=
new
StandType
();
location
.
setPriceInCents
(
price
);
...
...
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