Skip to content

Commit 8bc3f5d

Browse files
committed
improve: a page with country info now shows the series with images.
Fix #1228
1 parent 4028cb6 commit 8bc3f5d

File tree

14 files changed

+159
-45
lines changed

14 files changed

+159
-45
lines changed

NEWS.txt

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
0.x (upcoming release)
2-
- (feature) a series can be marked as a similar to another one
3-
- (feature) series images can be replaced
4-
- (feature) add preliminary support for hidden images
5-
- (feature) admin can add a comment to a series
2+
- (feature) a series can be marked as a similar to another one
3+
- (feature) series images can be replaced
4+
- (feature) add preliminary support for hidden images
5+
- (feature) admin can add a comment to a series
6+
- (improvement) on a country info page show the series with an image
67

78
0.4.3
89
- (feature) add support for Ukrainian hryvnia

src/main/java/ru/mystamps/web/feature/series/JdbcSeriesDao.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -243,12 +243,12 @@ public List<SeriesInfoDto> findByCategorySlugAsSeriesInfo(String slug, String la
243243
}
244244

245245
@Override
246-
public List<SeriesInfoDto> findByCountrySlugAsSeriesInfo(String slug, String lang) {
246+
public List<SeriesInGalleryDto> findByCountrySlug(String slug, String lang) {
247247
Map<String, Object> params = new HashMap<>();
248248
params.put("slug", slug);
249249
params.put("lang", lang);
250250

251-
return jdbcTemplate.query(findByCountrySlugSql, params, RowMappers::forSeriesInfoDto);
251+
return jdbcTemplate.query(findByCountrySlugSql, params, RowMappers::forSeriesInGalleryDto);
252252
}
253253

254254
/**

src/main/java/ru/mystamps/web/feature/series/RowMappers.java

+22
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929

3030
import static ru.mystamps.web.common.RowMappers.createLinkEntityDto;
3131

32+
// complains on "release_year", "quantity" and "perforated"
33+
@SuppressWarnings("PMD.AvoidDuplicateLiterals")
3234
final class RowMappers {
3335

3436
private RowMappers() {
@@ -82,6 +84,26 @@ private RowMappers() {
8284
);
8385
}
8486

87+
/* default */ static SeriesInGalleryDto forSeriesInGalleryDto(ResultSet rs, int unused)
88+
throws SQLException {
89+
90+
Integer seriesId = rs.getInt("id");
91+
Integer releaseYear = JdbcUtils.getInteger(rs, "release_year");
92+
Integer quantity = rs.getInt("quantity");
93+
Boolean perforated = rs.getBoolean("perforated");
94+
Integer previewId = JdbcUtils.getInteger(rs, "preview_id");
95+
String category = rs.getString("category");
96+
97+
return new SeriesInGalleryDto(
98+
seriesId,
99+
releaseYear,
100+
quantity,
101+
perforated,
102+
previewId,
103+
category
104+
);
105+
}
106+
85107
/**
86108
* @author Sergey Chechenev
87109
*/

src/main/java/ru/mystamps/web/feature/series/SeriesController.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ public String showInfoByCountrySlug(
252252
String name = country.getName();
253253

254254
String lang = LocaleUtils.getLanguageOrNull(userLocale);
255-
List<SeriesInfoDto> series = seriesService.findByCountrySlug(slug, lang);
255+
List<SeriesInGalleryDto> series = seriesService.findByCountrySlug(slug, lang);
256256

257257
model.addAttribute("countrySlug", slug);
258258
model.addAttribute("countryName", name);

src/main/java/ru/mystamps/web/feature/series/SeriesDao.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public interface SeriesDao {
3232
SeriesFullInfoDto findByIdAsSeriesFullInfo(Integer seriesId, String lang);
3333
List<SeriesInfoDto> findByIdsAsSeriesInfo(List<Integer> seriesIds, String lang);
3434
List<SeriesInfoDto> findByCategorySlugAsSeriesInfo(String slug, String lang);
35-
List<SeriesInfoDto> findByCountrySlugAsSeriesInfo(String slug, String lang);
35+
List<SeriesInGalleryDto> findByCountrySlug(String slug, String lang);
3636
List<PurchaseAndSaleDto> findPurchasesAndSales(Integer seriesId);
3737

3838
long countAll();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright (C) 2009-2020 Slava Semushin <[email protected]>
3+
*
4+
* This program is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation; either version 2 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program; if not, write to the Free Software
16+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17+
*/
18+
package ru.mystamps.web.feature.series;
19+
20+
import lombok.Getter;
21+
import lombok.RequiredArgsConstructor;
22+
23+
@Getter
24+
@RequiredArgsConstructor
25+
public class SeriesInGalleryDto {
26+
private final Integer id;
27+
private final Integer releaseYear;
28+
private final Integer quantity;
29+
private final Boolean perforated;
30+
private final Integer previewId;
31+
private final String category;
32+
}

src/main/java/ru/mystamps/web/feature/series/SeriesService.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public interface SeriesService {
4444
List<SeriesInfoDto> findByZagorskiNumber(String zagorskiCatalogNumber, String lang);
4545

4646
List<SeriesInfoDto> findByCategorySlug(String slug, String lang);
47-
List<SeriesInfoDto> findByCountrySlug(String slug, String lang);
47+
List<SeriesInGalleryDto> findByCountrySlug(String slug, String lang);
4848
List<SeriesLinkDto> findRecentlyAdded(int quantity, String lang);
4949
List<SeriesLinkDto> findSimilarSeries(Integer seriesId, String lang);
5050
List<SitemapInfoDto> findAllForSitemap();

src/main/java/ru/mystamps/web/feature/series/SeriesServiceImpl.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -303,10 +303,10 @@ public List<SeriesInfoDto> findByCategorySlug(String slug, String lang) {
303303

304304
@Override
305305
@Transactional(readOnly = true)
306-
public List<SeriesInfoDto> findByCountrySlug(String slug, String lang) {
306+
public List<SeriesInGalleryDto> findByCountrySlug(String slug, String lang) {
307307
Validate.isTrue(slug != null, "Country slug must be non null");
308308

309-
return seriesDao.findByCountrySlugAsSeriesInfo(slug, lang);
309+
return seriesDao.findByCountrySlug(slug, lang);
310310
}
311311

312312
@Override

src/main/java/ru/mystamps/web/feature/site/ResourceUrl.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public final class ResourceUrl {
3232
public static final String STATIC_RESOURCES_URL = "https://stamps.filezz.ru";
3333

3434
// MUST be updated when any of our resources were modified
35-
public static final String RESOURCES_VERSION = "v0.4.3.9";
35+
public static final String RESOURCES_VERSION = "v0.4.3.10";
3636

3737
// CheckStyle: ignore LineLength for next 15 lines
3838
private static final String CATALOG_UTILS_JS = "/public/js/" + RESOURCES_VERSION + "/CatalogUtils.min.js";

src/main/resources/sql/series_dao_queries.properties

+11-9
Original file line numberDiff line numberDiff line change
@@ -158,23 +158,25 @@ LEFT JOIN countries count \
158158
ON count.id = s.country_id \
159159
WHERE cat.slug = :slug
160160

161+
# @todo #1282 Consider adding a field with an image used for preview
161162
series.find_by_country_slug = \
162163
SELECT s.id \
163-
, cat.id AS category_id \
164-
, cat.slug AS category_slug \
165-
, CASE WHEN 'ru' = :lang THEN COALESCE(cat.name_ru, cat.name) ELSE cat.name END AS category_name \
166-
, count.id AS country_id \
167-
, count.slug AS country_slug \
168-
, CASE WHEN 'ru' = :lang THEN COALESCE(count.name_ru, count.name) ELSE count.name END AS country_name \
169-
, s.release_day \
170-
, s.release_month \
164+
, CASE WHEN 'ru' = :lang THEN COALESCE(cat.name_ru, cat.name) ELSE cat.name END AS category \
171165
, s.release_year \
172166
, s.quantity \
173167
, s.perforated \
168+
, ( \
169+
SELECT si.image_id \
170+
FROM series_images si \
171+
WHERE si.series_id = s.id \
172+
AND si.hidden = FALSE \
173+
ORDER BY si.image_id \
174+
LIMIT 1 \
175+
) AS preview_id \
174176
FROM series s \
175177
JOIN categories cat \
176178
ON cat.id = s.category_id \
177-
LEFT JOIN countries count \
179+
JOIN countries count \
178180
ON count.id = s.country_id \
179181
WHERE count.slug = :slug
180182

src/main/webapp/WEB-INF/static/styles/main.css

+13
Original file line numberDiff line numberDiff line change
@@ -108,3 +108,16 @@ label {
108108
.number-input {
109109
width: 4em;
110110
}
111+
112+
.image-gallery {
113+
display: flex;
114+
flex-wrap: wrap;
115+
}
116+
.image-gallery figure {
117+
/* margin: <top> <right> <bottom> <left> */
118+
margin: 15px 0 15px 15px;
119+
}
120+
.image-gallery figcaption {
121+
margin-top: 5px;
122+
text-align: center;
123+
}

src/main/webapp/WEB-INF/views/country/info.html

+52-20
Original file line numberDiff line numberDiff line change
@@ -87,33 +87,65 @@ <h3 id="page-header" th:text="${#strings.capitalize(header)}">
8787
</div>
8888
/*/-->
8989

90-
<ul th:if="${not #lists.isEmpty(seriesOfCountry)}" th:remove="all-but-first">
91-
<li th:each="series : ${seriesOfCountry}">
92-
<span th:if="${series.category != null}" th:remove="tag">
93-
<a href="../category/info.html" th:href="@{${INFO_CATEGORY_PAGE}(slug=${series.category.slug})}" th:text="${series.category.name}">Animals</a>&nbsp;&raquo;
94-
</span>
90+
<div class="image-gallery" th:if="${not #lists.isEmpty(seriesOfCountry)}" th:remove="all-but-first">
91+
92+
<figure th:each="series : ${seriesOfCountry}"
93+
th:with="desc=|${series.category}, ${series.releaseYear != null ? series.releaseYear + ', ' : ''}${series.quantity}&nbsp;${series.quantity != 1 ? '__#{t_stamps}__' : '__#{t_stamp}__'}${not series.perforated ? ' (__#{t_wo_perforation_short}__)' : ''}|">
9594

9695
<a href="../series/info.html" th:href="@{${INFO_SERIES_PAGE}(id=${series.id})}">
97-
<span th:remove="tag" th:if="${series.releaseYear != null}" th:text="|${series.releaseYear}, |">1980, </span>
98-
<span th:remove="tag" th:text="|${series.quantity}&nbsp;${series.quantity != 1 ? '__#{t_stamps}__' : '__#{t_stamp}__'}|">10&nbsp;stamps</span>
99-
<span th:remove="tag" th:if="${not series.perforated}" th:text="|(#{t_wo_perforation_short})|">(imperf.)</span>
96+
<img src="https://picsum.photos/250"
97+
th:with="label=|${countryName}, ${desc}|"
98+
alt="Italy, Prehistoric animals, 1999, 7&nbsp;stamps (imperf.)"
99+
title="Italy, Prehistoric animals, 1999, 7&nbsp;stamps (imperf.)"
100+
th:alt="${label}"
101+
th:title="${label}"
102+
th:src="@{${GET_IMAGE_PREVIEW_PAGE}(id=${series.previewId})}" />
100103
</a>
101-
</li>
102-
<li>
103-
<a href="../category/info.html">Animals</a>&nbsp;&raquo;
104-
104+
<figcaption>
105+
<a href="../series/info.html" th:href="@{${INFO_SERIES_PAGE}(id=${series.id})}" th:text="${desc}">
106+
Prehistoric animals, 1999, 7&nbsp;stamps (imperf.)
107+
</a>
108+
</figcaption>
109+
</figure>
110+
<figure>
105111
<a href="../series/info.html">
106-
22&nbsp;stamps
112+
<img src="https://picsum.photos/250" alt="Italy, Prehistoric animals, 22&nbsp;stamps" title="Italy, Prehistoric animals, 22&nbsp;stamps" />
107113
</a>
108-
</li>
109-
<li>
110-
<a href="../category/info.html">Animals</a>&nbsp;&raquo;
111-
114+
<figcaption><a href="../series/info.html">Prehistoric animals, 22&nbsp;stamps</a></figcaption>
115+
</figure>
116+
<figure>
112117
<a href="../series/info.html">
113-
1983, 5&nbsp;stamps
118+
<img src="https://picsum.photos/250" alt="Italy, Cartoons, 2005, 5&nbsp;stamps" title="Italy, Cartoons, 2005, 5&nbsp;stamps" />
114119
</a>
115-
</li>
116-
</ul>
120+
<figcaption><a href="../series/info.html">Cartoons, 2005, 5&nbsp;stamps</a></figcaption>
121+
</figure>
122+
<figure>
123+
<a href="../series/info.html">
124+
<img src="https://picsum.photos/250" alt="Italy, Prehistoric animals, 22&nbsp;stamps" title="Italy, Prehistoric animals, 22&nbsp;stamps" />
125+
</a>
126+
<figcaption><a href="../series/info.html">Prehistoric animals, 22&nbsp;stamps</a></figcaption>
127+
</figure>
128+
<figure>
129+
<a href="../series/info.html">
130+
<img src="https://picsum.photos/250" alt="Italy, Prehistoric animals, 1983, 5&nbsp;stamps" title="Italy, Prehistoric animals, 1983, 5&nbsp;stamps" />
131+
</a>
132+
<figcaption><a href="../series/info.html">Prehistoric animals, 1983, 5&nbsp;stamps</a></figcaption>
133+
</figure>
134+
<figure>
135+
<a href="../series/info.html">
136+
<img src="https://picsum.photos/250" alt="Italy, Famous People, 2003, 4&nbsp;stamps" title="Italy, Famous People, 2003, 4&nbsp;stamps" />
137+
</a>
138+
<figcaption><a href="../series/info.html">Famous People, 2003, 4&nbsp;stamps</a></figcaption>
139+
</figure>
140+
<figure>
141+
<a href="../series/info.html">
142+
<img src="https://picsum.photos/250" alt="Italy, Sport, 1996, 1&nbsp;stamp" title="Italy, Sport, 1996, 1&nbsp;stamp" />
143+
</a>
144+
<figcaption><a href="../series/info.html">Sport, 1996, 1&nbsp;stamp</a></figcaption>
145+
</figure>
146+
147+
</div>
148+
117149
</div>
118150
</div>
119151
<div class="row">

src/test/groovy/ru/mystamps/web/feature/series/SeriesServiceImplTest.groovy

+4-4
Original file line numberDiff line numberDiff line change
@@ -1059,13 +1059,13 @@ class SeriesServiceImplTest extends Specification {
10591059

10601060
def "findByCountrySlug() should call dao and return result"() {
10611061
given:
1062-
SeriesInfoDto series = TestObjects.createSeriesInfoDto()
1062+
SeriesInGalleryDto series = TestObjects.createSeriesInGalleryDto()
10631063
and:
1064-
List<SeriesInfoDto> expectedResult = [ series ]
1064+
List<SeriesInGalleryDto> expectedResult = [ series ]
10651065
and:
1066-
seriesDao.findByCountrySlugAsSeriesInfo(_ as String, _ as String) >> expectedResult
1066+
seriesDao.findByCountrySlug(_ as String, _ as String) >> expectedResult
10671067
when:
1068-
List<SeriesInfoDto> result = service.findByCountrySlug('germany', Random.lang())
1068+
List<SeriesInGalleryDto> result = service.findByCountrySlug('germany', Random.lang())
10691069
then:
10701070
result == expectedResult
10711071
}

src/test/java/ru/mystamps/web/service/TestObjects.java

+12
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import ru.mystamps.web.feature.series.AddSeriesForm;
3838
import ru.mystamps.web.feature.series.PurchaseAndSaleDto;
3939
import ru.mystamps.web.feature.series.SeriesFullInfoDto;
40+
import ru.mystamps.web.feature.series.SeriesInGalleryDto;
4041
import ru.mystamps.web.feature.series.SeriesInfoDto;
4142
import ru.mystamps.web.feature.series.SeriesLinkDto;
4243
import ru.mystamps.web.feature.series.SitemapInfoDto;
@@ -154,6 +155,17 @@ public static SeriesInfoDto createSeriesInfoDto() {
154155
);
155156
}
156157

158+
public static SeriesInGalleryDto createSeriesInGalleryDto() {
159+
return new SeriesInGalleryDto(
160+
Random.id(),
161+
nullOr(Random.issueYear()),
162+
Random.quantity(),
163+
Random.perforated(),
164+
Random.id(),
165+
Random.categoryName()
166+
);
167+
}
168+
157169
public static SeriesFullInfoDto createSeriesFullInfoDto() {
158170
SeriesInfoDto info = createSeriesInfoDto();
159171
return new SeriesFullInfoDto(

0 commit comments

Comments
 (0)