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

Lines changed: 5 additions & 4 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 22 additions & 0 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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();
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright (C) 2009-2020 Slava Semushin <slava.semushin@gmail.com>
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 11 additions & 9 deletions
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

0 commit comments

Comments
 (0)