Skip to content

Commit d9254f8

Browse files
committed
SeriesService.findBy(Category): renamed to findByCategoryId() to replace usage of Category entity.
Addressed to #120 No functional changes.
1 parent 39269f5 commit d9254f8

File tree

4 files changed

+11
-12
lines changed

4 files changed

+11
-12
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ public String showInfo(
103103
model.addAttribute("category", category);
104104

105105
String lang = LocaleUtils.getLanguageOrNull(userLocale);
106-
model.addAttribute("seriesOfCategory", seriesService.findBy(category, lang));
106+
Integer categoryId = category.getId();
107+
model.addAttribute("seriesOfCategory", seriesService.findByCategoryId(categoryId, lang));
107108

108109
return "category/info";
109110
}

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.Category;
2322
import ru.mystamps.web.entity.Collection;
2423
import ru.mystamps.web.entity.Country;
2524
import ru.mystamps.web.entity.Series;
@@ -49,7 +48,7 @@ public interface SeriesService {
4948
Optional<Integer> findSeriesIdByYvertNumber(String yvertNumberCode);
5049
Optional<Integer> findSeriesIdByGibbonsNumber(String gibbonsNumberCode);
5150

52-
Iterable<SeriesInfoDto> findBy(Category category, String lang);
51+
Iterable<SeriesInfoDto> findByCategoryId(Integer categoryId, String lang);
5352
Iterable<SeriesInfoDto> findBy(Country country, String lang);
5453
Iterable<SeriesInfoDto> findBy(Collection collection, String lang);
5554
Iterable<SeriesInfoDto> findRecentlyAdded(int quantity, String lang);

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434

3535
import ru.mystamps.web.dao.JdbcSeriesDao;
3636
import ru.mystamps.web.dao.SeriesDao;
37-
import ru.mystamps.web.entity.Category;
3837
import ru.mystamps.web.entity.Country;
3938
import ru.mystamps.web.entity.Collection;
4039
import ru.mystamps.web.entity.Currency;
@@ -255,10 +254,10 @@ public Optional<Integer> findSeriesIdByGibbonsNumber(String gibbonsNumberCode) {
255254

256255
@Override
257256
@Transactional(readOnly = true)
258-
public Iterable<SeriesInfoDto> findBy(Category category, String lang) {
259-
Validate.isTrue(category != null, "Category must be non null");
257+
public Iterable<SeriesInfoDto> findByCategoryId(Integer categoryId, String lang) {
258+
Validate.isTrue(categoryId != null, "Category id must be non null");
260259

261-
return jdbcSeriesDao.findByCategoryIdAsSeriesInfo(category.getId(), lang);
260+
return jdbcSeriesDao.findByCategoryIdAsSeriesInfo(categoryId, lang);
262261
}
263262

264263
@Override

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -720,25 +720,25 @@ class SeriesServiceImplTest extends Specification {
720720
}
721721

722722
//
723-
// Tests for findBy(Category)
723+
// Tests for findByCategoryId()
724724
//
725725

726-
def "findBy(Category) should throw exception if category is null"() {
726+
def "findByCategoryId() should throw exception if category id is null"() {
727727
when:
728-
service.findBy(null as Category, 'any')
728+
service.findByCategoryId(null, 'any')
729729
then:
730730
thrown IllegalArgumentException
731731
}
732732

733-
def "findBy(Category) should call dao and return result"() {
733+
def "findByCategoryId() should call dao and return result"() {
734734
given:
735735
Category expectedCategory = TestObjects.createCategory()
736736
and:
737737
Iterable<Category> expectedResult = [ expectedCategory ]
738738
and:
739739
jdbcSeriesDao.findByCategoryIdAsSeriesInfo(_ as Integer, _ as String) >> expectedResult
740740
when:
741-
Iterable<Category> result = service.findBy(expectedCategory, 'any')
741+
Iterable<Category> result = service.findByCategoryId(10, 'any')
742742
then:
743743
result == expectedResult
744744
}

0 commit comments

Comments
 (0)