Skip to content

Commit 6f8f655

Browse files
committed
SeriesService.findBy(Collection): renamed to findByCollectionId() to replace usage of Collection entity.
Addressed to #120 No functional changes.
1 parent d9254f8 commit 6f8f655

File tree

4 files changed

+12
-28
lines changed

4 files changed

+12
-28
lines changed

src/main/java/ru/mystamps/web/controller/CollectionController.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,12 @@ public String showInfo(
6464
model.addAttribute("ownerName", collection.getOwner().getName());
6565

6666
String lang = LocaleUtils.getLanguageOrNull(userLocale);
67-
Iterable<SeriesInfoDto> seriesOfCollection = seriesService.findBy(collection, lang);
67+
Integer collectionId = collection.getId();
68+
Iterable<SeriesInfoDto> seriesOfCollection =
69+
seriesService.findByCollectionId(collectionId, lang);
6870
model.addAttribute("seriesOfCollection", seriesOfCollection);
6971

7072
if (seriesOfCollection.iterator().hasNext()) {
71-
Integer collectionId = collection.getId();
7273
model.addAttribute("categoryCounter", categoryService.countCategoriesOf(collection));
7374
model.addAttribute("countryCounter", countryService.countCountriesOf(collection));
7475
model.addAttribute("seriesCounter", seriesService.countSeriesOf(collectionId));

src/main/java/ru/mystamps/web/service/SeriesService.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
import java.util.Optional;
2121

22-
import ru.mystamps.web.entity.Collection;
2322
import ru.mystamps.web.entity.Country;
2423
import ru.mystamps.web.entity.Series;
2524
import ru.mystamps.web.entity.User;
@@ -50,7 +49,7 @@ public interface SeriesService {
5049

5150
Iterable<SeriesInfoDto> findByCategoryId(Integer categoryId, String lang);
5251
Iterable<SeriesInfoDto> findBy(Country country, String lang);
53-
Iterable<SeriesInfoDto> findBy(Collection collection, String lang);
52+
Iterable<SeriesInfoDto> findByCollectionId(Integer collectionId, String lang);
5453
Iterable<SeriesInfoDto> findRecentlyAdded(int quantity, String lang);
5554
Iterable<SitemapInfoDto> findAllForSitemap();
5655
}

src/main/java/ru/mystamps/web/service/SeriesServiceImpl.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
import ru.mystamps.web.dao.JdbcSeriesDao;
3636
import ru.mystamps.web.dao.SeriesDao;
3737
import ru.mystamps.web.entity.Country;
38-
import ru.mystamps.web.entity.Collection;
3938
import ru.mystamps.web.entity.Currency;
4039
import ru.mystamps.web.entity.GibbonsCatalog;
4140
import ru.mystamps.web.entity.Image;
@@ -270,11 +269,10 @@ public Iterable<SeriesInfoDto> findBy(Country country, String lang) {
270269

271270
@Override
272271
@Transactional(readOnly = true)
273-
public Iterable<SeriesInfoDto> findBy(Collection collection, String lang) {
274-
Validate.isTrue(collection != null, "Collection must be non null");
275-
Validate.isTrue(collection.getId() != null, "Collection id must be non null");
272+
public Iterable<SeriesInfoDto> findByCollectionId(Integer collectionId, String lang) {
273+
Validate.isTrue(collectionId != null, "Collection id must be non null");
276274

277-
return jdbcSeriesDao.findByCollectionIdAsSeriesInfo(collection.getId(), lang);
275+
return jdbcSeriesDao.findByCollectionIdAsSeriesInfo(collectionId, lang);
278276
}
279277

280278
@Override

src/test/groovy/ru/mystamps/web/service/SeriesServiceImplTest.groovy

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import ru.mystamps.web.dao.JdbcSeriesDao
2626
import ru.mystamps.web.dao.SeriesDao
2727
import ru.mystamps.web.entity.Category
2828
import ru.mystamps.web.entity.Country
29-
import ru.mystamps.web.entity.Collection
3029
import ru.mystamps.web.entity.Currency
3130
import ru.mystamps.web.entity.GibbonsCatalog
3231
import ru.mystamps.web.entity.Image
@@ -768,36 +767,23 @@ class SeriesServiceImplTest extends Specification {
768767
}
769768

770769
//
771-
// Tests for findBy(Collection)
770+
// Tests for findByCollectionId()
772771
//
773772

774-
def "findBy(Collection) should throw exception when collection is null"() {
773+
def "findByCollectionId() should throw exception when collection id is null"() {
775774
when:
776-
service.findBy(null as Collection, 'whatever')
775+
service.findByCollectionId(null, 'whatever')
777776
then:
778777
thrown IllegalArgumentException
779778
}
780779

781-
def "findBy(Collection) should throw exception when collection id is null"() {
782-
given:
783-
Collection collection = Mock()
784-
collection.getId() >> null
785-
when:
786-
service.findBy(collection, 'whatever')
787-
then:
788-
thrown IllegalArgumentException
789-
}
790-
791-
def "findBy(Collection) should pass arguments to dao"() {
780+
def "findByCollectionId() should pass arguments to dao"() {
792781
given:
793782
Integer expectedCollectionId = 16
794783
and:
795784
String expectedLang = 'expected'
796-
and:
797-
Collection expectedCollection = Mock()
798-
expectedCollection.getId() >> expectedCollectionId
799785
when:
800-
service.findBy(expectedCollection, expectedLang)
786+
service.findByCollectionId(expectedCollectionId, expectedLang)
801787
then:
802788
1 * jdbcSeriesDao.findByCollectionIdAsSeriesInfo(
803789
{ Integer collectionId ->

0 commit comments

Comments
 (0)