Skip to content

Commit a9a0226

Browse files
committed
Show amount of stamps in database.
1 parent 7a1e0b4 commit a9a0226

File tree

8 files changed

+30
-0
lines changed

8 files changed

+30
-0
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public SiteController(CountryService countryService, SeriesService seriesService
4141
public String showIndexPage(Model model) {
4242
model.addAttribute("countryCounter", countryService.countAll());
4343
model.addAttribute("seriesCounter", seriesService.countAll());
44+
model.addAttribute("stampsCounter", seriesService.countAllStamps());
4445
return "site/index";
4546
}
4647

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,6 @@ public interface SeriesDao extends CrudRepository<Series, Integer> {
3737
@Query("SELECT COUNT(*) FROM Series s INNER JOIN s.gibbons m WHERE m.code = :gibbonsCode")
3838
int countByGibbonsNumberCode(@Param("gibbonsCode") String gibbonsNumberCode);
3939

40+
@Query("SELECT SUM(quantity) FROM Series")
41+
long countAllStamps();
4042
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
public interface SeriesService {
2525
Series add(AddSeriesDto dto, User user, boolean userCanAddComments);
2626
long countAll();
27+
long countAllStamps();
2728
int countByMichelNumber(String michelNumberCode);
2829
int countByScottNumber(String scottNumberCode);
2930
int countByYvertNumber(String yvertNumberCode);

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,12 @@ public long countAll() {
132132
return seriesDao.count();
133133
}
134134

135+
@Override
136+
@Transactional(readOnly = true)
137+
public long countAllStamps() {
138+
return seriesDao.countAllStamps();
139+
}
140+
135141
@Override
136142
@Transactional(readOnly = true)
137143
public int countByMichelNumber(String michelNumberCode) {

src/main/resources/ru/mystamps/i18n/Messages.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ t_you_may = You may
2525
t_in_db = In our database
2626
t_countries_amount = Amount of countries
2727
t_series_amount = Amount of series
28+
t_stamps_amount = Amount of stamps
2829

2930
# account/register.jsp
3031
t_registration_on_site = Register on site

src/main/resources/ru/mystamps/i18n/Messages_ru.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ t_you_may = Вы можете
2525
t_in_db = В нашей базе
2626
t_countries_amount = Стран
2727
t_series_amount = Серий
28+
t_stamps_amount = Марок
2829

2930
# account/register.jsp
3031
t_registration_on_site = Регистрация на сайте

src/main/webapp/WEB-INF/tiles/body/site/index.jsp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,7 @@
3030
<p>
3131
<spring:message code="t_series_amount" />: ${seriesCounter}
3232
</p>
33+
<p>
34+
<spring:message code="t_stamps_amount" />: ${stampsCounter}
35+
</p>
3336
</div>

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,21 @@ class SeriesServiceTest extends Specification {
568568
result == expectedResult
569569
}
570570

571+
//
572+
// Tests for countAllStamps()
573+
//
574+
575+
def "countAllStamps() should call dao and returns result"() {
576+
given:
577+
long expectedResult = 30
578+
when:
579+
long result = service.countAllStamps()
580+
then:
581+
1 * seriesDao.countAllStamps() >> expectedResult
582+
and:
583+
result == expectedResult
584+
}
585+
571586
//
572587
// Tests for countByMichelNumber()
573588
//

0 commit comments

Comments
 (0)