Skip to content

Commit d9928a4

Browse files
committed
SeriesService.countStampsOf(): rename to CollectionService.countStampsOf().
Fix #878
1 parent 4b3f9cb commit d9928a4

13 files changed

+48
-49
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public String showInfoBySlug(
8787
long categoryCounter = categoryService.countCategoriesOf(collectionId);
8888
long countryCounter = countryService.countCountriesOf(collectionId);
8989
long seriesCounter = seriesService.countSeriesOf(collectionId);
90-
long stampsCounter = seriesService.countStampsOf(collectionId);
90+
long stampsCounter = collectionService.countStampsOf(collectionId);
9191

9292
List<Object[]> categoriesStat = categoryService.getStatisticsOf(collectionId, lang);
9393
List<Object[]> countriesStat = getCountriesStatistics(collectionId, lang);

src/main/java/ru/mystamps/web/dao/CollectionDao.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public interface CollectionDao {
3131
List<SeriesInCollectionWithPriceDto> findSeriesWithPricesBySlug(String slug, String lang);
3232
long countCollectionsOfUsers();
3333
long countUpdatedSince(Date date);
34+
long countStampsOfCollection(Integer collectionId);
3435
Integer add(AddCollectionDbDto collection);
3536
void markAsModified(Integer userId, Date updatedAt);
3637
boolean isSeriesInUserCollection(Integer userId, Integer seriesId);

src/main/java/ru/mystamps/web/dao/SeriesDao.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ public interface SeriesDao {
4545
long countAll();
4646
long countAllStamps();
4747
long countSeriesOfCollection(Integer collectionId);
48-
long countStampsOfCollection(Integer collectionId);
4948
long countSeriesById(Integer seriesId);
5049
long countAddedSince(Date date);
5150
long countUpdatedSince(Date date);

src/main/java/ru/mystamps/web/dao/impl/JdbcCollectionDao.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ public class JdbcCollectionDao implements CollectionDao {
6363
@Value("${collection.count_updated_since}")
6464
private String countUpdatedSinceSql;
6565

66+
@Value("${collection.count_stamps_of_collection}")
67+
private String countStampsOfCollectionSql;
68+
6669
@Value("${collection.create}")
6770
private String addCollectionSql;
6871

@@ -124,6 +127,15 @@ public long countUpdatedSince(Date date) {
124127
);
125128
}
126129

130+
@Override
131+
public long countStampsOfCollection(Integer collectionId) {
132+
return jdbcTemplate.queryForObject(
133+
countStampsOfCollectionSql,
134+
Collections.singletonMap("collection_id", collectionId),
135+
Long.class
136+
);
137+
}
138+
127139
@Override
128140
public Integer add(AddCollectionDbDto collection) {
129141
Map<String, Object> params = new HashMap<>();

src/main/java/ru/mystamps/web/dao/impl/JdbcSeriesDao.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,6 @@ public class JdbcSeriesDao implements SeriesDao {
9494
@Value("${series.count_series_of_collection}")
9595
private String countSeriesOfCollectionSql;
9696

97-
@Value("${series.count_stamps_of_collection}")
98-
private String countStampsOfCollectionSql;
99-
10097
@Value("${series.count_series_by_id}")
10198
private String countSeriesByIdSql;
10299

@@ -279,15 +276,6 @@ public long countSeriesOfCollection(Integer collectionId) {
279276
);
280277
}
281278

282-
@Override
283-
public long countStampsOfCollection(Integer collectionId) {
284-
return jdbcTemplate.queryForObject(
285-
countStampsOfCollectionSql,
286-
Collections.singletonMap("collection_id", collectionId),
287-
Long.class
288-
);
289-
}
290-
291279
@Override
292280
public long countSeriesById(Integer seriesId) {
293281
return jdbcTemplate.queryForObject(

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public interface CollectionService {
3232
boolean isSeriesInCollection(Integer userId, Integer seriesId);
3333
long countCollectionsOfUsers();
3434
long countUpdatedSince(Date date);
35+
long countStampsOf(Integer collectionId);
3536
List<LinkEntityDto> findRecentlyCreated(int quantity);
3637
List<SeriesInCollectionWithPriceDto> findSeriesWithPricesBySlug(String slug, String lang);
3738
CollectionInfoDto findBySlug(String slug);

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,14 @@ public long countUpdatedSince(Date date) {
143143
return collectionDao.countUpdatedSince(date);
144144
}
145145

146+
@Override
147+
@Transactional(readOnly = true)
148+
public long countStampsOf(Integer collectionId) {
149+
Validate.isTrue(collectionId != null, "Collection id must be non null");
150+
151+
return collectionDao.countStampsOfCollection(collectionId);
152+
}
153+
146154
@Override
147155
@Transactional(readOnly = true)
148156
public List<LinkEntityDto> findRecentlyCreated(int quantity) {

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ public interface SeriesService {
3737
long countAll();
3838
long countAllStamps();
3939
long countSeriesOf(Integer collectionId);
40-
// @todo #477 SeriesService.countStampsOf(): rename to CollectionService.countStampsOf()
41-
long countStampsOf(Integer collectionId);
4240
long countAddedSince(Date date);
4341
long countUpdatedSince(Date date);
4442
boolean isSeriesExist(Integer seriesId);

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

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -186,14 +186,6 @@ public long countSeriesOf(Integer collectionId) {
186186
return seriesDao.countSeriesOfCollection(collectionId);
187187
}
188188

189-
@Override
190-
@Transactional(readOnly = true)
191-
public long countStampsOf(Integer collectionId) {
192-
Validate.isTrue(collectionId != null, "Collection id must be non null");
193-
194-
return seriesDao.countStampsOfCollection(collectionId);
195-
}
196-
197189
@Override
198190
@Transactional(readOnly = true)
199191
public long countAddedSince(Date date) {

src/main/resources/sql/collection_dao_queries.properties

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ SELECT COUNT(*) \
4242
FROM collections \
4343
WHERE updated_at >= :date
4444

45+
collection.count_stamps_of_collection = \
46+
SELECT COALESCE(SUM(cs.number_of_stamps), 0) AS counter \
47+
FROM collections_series cs \
48+
WHERE cs.collection_id = :collection_id
49+
4550
collection.create = \
4651
INSERT \
4752
INTO collections \

src/main/resources/sql/series_dao_queries.properties

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -206,11 +206,6 @@ SELECT COUNT(*) AS counter \
206206
FROM collections_series cs \
207207
WHERE cs.collection_id = :collection_id
208208

209-
series.count_stamps_of_collection = \
210-
SELECT COALESCE(SUM(cs.number_of_stamps), 0) AS counter \
211-
FROM collections_series cs \
212-
WHERE cs.collection_id = :collection_id
213-
214209
series.count_series_by_id = \
215210
SELECT COUNT(*) \
216211
FROM series \

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,26 @@ class CollectionServiceImplTest extends Specification {
308308
result == expectedResult
309309
}
310310

311+
//
312+
// Tests for countStampsOf()
313+
//
314+
315+
def 'countStampsOf() should throw exception when argument is null'() {
316+
when:
317+
service.countStampsOf(null)
318+
then:
319+
thrown IllegalArgumentException
320+
}
321+
322+
def 'countStampsOf() should pass arguments to dao'() {
323+
given:
324+
Integer expectedCollectionId = Random.id()
325+
when:
326+
service.countStampsOf(expectedCollectionId)
327+
then:
328+
1 * collectionDao.countStampsOfCollection(expectedCollectionId) >> positiveLong()
329+
}
330+
311331
//
312332
// Tests for findRecentlyCreated()
313333
//

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

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -592,26 +592,6 @@ class SeriesServiceImplTest extends Specification {
592592
1 * seriesDao.countSeriesOfCollection(expectedCollectionId) >> positiveLong()
593593
}
594594

595-
//
596-
// Tests for countStampsOf()
597-
//
598-
599-
def "countStampsOf() should throw exception when argument is null"() {
600-
when:
601-
service.countStampsOf(null)
602-
then:
603-
thrown IllegalArgumentException
604-
}
605-
606-
def "countStampsOf() should pass arguments to dao"() {
607-
given:
608-
Integer expectedCollectionId = Random.id()
609-
when:
610-
service.countStampsOf(expectedCollectionId)
611-
then:
612-
1 * seriesDao.countStampsOfCollection(expectedCollectionId) >> positiveLong()
613-
}
614-
615595
//
616596
// Tests for countAddedSince()
617597
//

0 commit comments

Comments
 (0)