Skip to content

Commit 565e2fb

Browse files
committed
/site/index: rework representation of the link to the series.
No functional changes.
1 parent d6b554d commit 565e2fb

File tree

9 files changed

+73
-52
lines changed

9 files changed

+73
-52
lines changed

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
import ru.mystamps.web.Url;
3131
import ru.mystamps.web.dao.dto.LinkEntityDto;
32-
import ru.mystamps.web.dao.dto.SeriesInfoDto;
32+
import ru.mystamps.web.dao.dto.SeriesLinkDto;
3333
import ru.mystamps.web.dao.dto.SuspiciousActivityDto;
3434
import ru.mystamps.web.service.CategoryService;
3535
import ru.mystamps.web.service.CollectionService;
@@ -66,7 +66,7 @@ public String showIndexPage(Model model, Locale userLocale) {
6666
long collectionsCounter = collectionService.countCollectionsOfUsers();
6767

6868
String lang = LocaleUtils.getLanguageOrNull(userLocale);
69-
List<SeriesInfoDto> recentlyAdded =
69+
List<SeriesLinkDto> recentlyAdded =
7070
seriesService.findRecentlyAdded(AMOUNT_OF_RECENTLY_ADDED_SERIES, lang);
7171

7272
List<LinkEntityDto> recentlyCreated =

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import ru.mystamps.web.dao.dto.SeriesFullInfoDto;
2626
import ru.mystamps.web.dao.dto.SeriesInCollectionDto;
2727
import ru.mystamps.web.dao.dto.SeriesInfoDto;
28+
import ru.mystamps.web.dao.dto.SeriesLinkDto;
2829
import ru.mystamps.web.dao.dto.SitemapInfoDto;
2930

3031
// TODO: move stamps related methods to separate interface (#88)
@@ -33,7 +34,7 @@ public interface SeriesDao {
3334
Integer add(AddSeriesDbDto series);
3435
void markAsModified(Integer seriesId, Date updateAt, Integer updatedBy);
3536
List<SitemapInfoDto> findAllForSitemap();
36-
List<SeriesInfoDto> findLastAdded(int quantity, String lang);
37+
List<SeriesLinkDto> findLastAdded(int quantity, String lang);
3738
SeriesFullInfoDto findByIdAsSeriesFullInfo(Integer seriesId, String lang);
3839
List<SeriesInfoDto> findByIdsAsSeriesInfo(List<Integer> seriesIds, String lang);
3940
List<SeriesInfoDto> findByCategorySlugAsSeriesInfo(String slug, String lang);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright (C) 2009-2018 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.dao.dto;
19+
20+
import lombok.Getter;
21+
import lombok.RequiredArgsConstructor;
22+
import lombok.ToString;
23+
24+
/**
25+
* Data for representation of a link to a series.
26+
*
27+
* Example of a link:
28+
* <code>
29+
* &lt;a href="/series/{id}"&gt;{country}, {year}, {quantity} stamps (without perforation)&lt;/a&gt;
30+
* </code>
31+
*/
32+
@Getter
33+
@ToString
34+
@RequiredArgsConstructor
35+
public class SeriesLinkDto {
36+
private final Integer id;
37+
private final Integer year;
38+
private final Integer quantity;
39+
private final Boolean perforated;
40+
private final String country;
41+
}

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import ru.mystamps.web.dao.dto.SeriesFullInfoDto;
4141
import ru.mystamps.web.dao.dto.SeriesInCollectionDto;
4242
import ru.mystamps.web.dao.dto.SeriesInfoDto;
43+
import ru.mystamps.web.dao.dto.SeriesLinkDto;
4344
import ru.mystamps.web.dao.dto.SitemapInfoDto;
4445

4546
// TODO: move stamps related methods to separate interface (#88)
@@ -179,12 +180,12 @@ public List<SitemapInfoDto> findAllForSitemap() {
179180
}
180181

181182
@Override
182-
public List<SeriesInfoDto> findLastAdded(int quantity, String lang) {
183+
public List<SeriesLinkDto> findLastAdded(int quantity, String lang) {
183184
Map<String, Object> params = new HashMap<>();
184185
params.put("quantity", quantity);
185186
params.put("lang", lang);
186187

187-
return jdbcTemplate.query(findLastAddedSeriesSql, params, RowMappers::forSeriesInfoDto);
188+
return jdbcTemplate.query(findLastAddedSeriesSql, params, RowMappers::forSeriesLinkDto);
188189
}
189190

190191
@Override

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

+10
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,16 @@ public static SitemapInfoDto forSitemapInfoDto(ResultSet rs, int unused) throws
5353
);
5454
}
5555

56+
public static SeriesLinkDto forSeriesLinkDto(ResultSet rs, int unused) throws SQLException {
57+
Integer id = rs.getInt("id");
58+
Integer year = JdbcUtils.getInteger(rs, "release_year");
59+
Integer quantity = rs.getInt("quantity");
60+
Boolean perforated = rs.getBoolean("perforated");
61+
String country = rs.getString("country_name");
62+
63+
return new SeriesLinkDto(id, year, quantity, perforated, country);
64+
}
65+
5666
public static SeriesInfoDto forSeriesInfoDto(ResultSet rs, int unused) throws SQLException {
5767
Integer seriesId = rs.getInt("id");
5868
Integer releaseDay = JdbcUtils.getInteger(rs, "release_day");

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import ru.mystamps.web.dao.dto.PurchaseAndSaleDto;
2424
import ru.mystamps.web.dao.dto.SeriesInCollectionDto;
2525
import ru.mystamps.web.dao.dto.SeriesInfoDto;
26+
import ru.mystamps.web.dao.dto.SeriesLinkDto;
2627
import ru.mystamps.web.dao.dto.SitemapInfoDto;
2728
import ru.mystamps.web.service.dto.AddImageDto;
2829
import ru.mystamps.web.service.dto.AddSeriesDto;
@@ -57,7 +58,7 @@ public interface SeriesService {
5758
// @todo #477 SeriesService.findByCollectionId():
5859
// rename to CollectionService.findSeriesInCollection()
5960
List<SeriesInCollectionDto> findByCollectionId(Integer collectionId, String lang);
60-
List<SeriesInfoDto> findRecentlyAdded(int quantity, String lang);
61+
List<SeriesLinkDto> findRecentlyAdded(int quantity, String lang);
6162
List<SitemapInfoDto> findAllForSitemap();
6263

6364
List<PurchaseAndSaleDto> findPurchasesAndSales(Integer seriesId);

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import ru.mystamps.web.dao.dto.SeriesFullInfoDto;
4040
import ru.mystamps.web.dao.dto.SeriesInCollectionDto;
4141
import ru.mystamps.web.dao.dto.SeriesInfoDto;
42+
import ru.mystamps.web.dao.dto.SeriesLinkDto;
4243
import ru.mystamps.web.dao.dto.SitemapInfoDto;
4344
import ru.mystamps.web.service.dto.AddImageDto;
4445
import ru.mystamps.web.service.dto.AddSeriesDto;
@@ -318,7 +319,7 @@ public List<SeriesInCollectionDto> findByCollectionId(Integer collectionId, Stri
318319

319320
@Override
320321
@Transactional(readOnly = true)
321-
public List<SeriesInfoDto> findRecentlyAdded(int quantity, String lang) {
322+
public List<SeriesLinkDto> findRecentlyAdded(int quantity, String lang) {
322323
Validate.isTrue(quantity > 0, "Quantity of recently added series must be greater than 0");
323324

324325
return seriesDao.findLastAdded(quantity, lang);

src/main/resources/sql/series_dao_queries.properties

-9
Original file line numberDiff line numberDiff line change
@@ -53,20 +53,11 @@ SELECT s.id, s.updated_at \
5353

5454
series.find_last_added = \
5555
SELECT s.id \
56-
, s.release_day \
57-
, s.release_month \
5856
, s.release_year \
5957
, s.quantity \
6058
, s.perforated \
61-
, cat.id AS category_id \
62-
, cat.slug AS category_slug \
63-
, CASE WHEN 'ru' = :lang THEN COALESCE(cat.name_ru, cat.name) ELSE cat.name END AS category_name \
64-
, count.id AS country_id \
65-
, count.slug AS country_slug \
6659
, CASE WHEN 'ru' = :lang THEN COALESCE(count.name_ru, count.name) ELSE count.name END AS country_name \
6760
FROM series s \
68-
JOIN categories cat \
69-
ON cat.id = s.category_id \
7061
LEFT JOIN countries count \
7162
ON count.id = s.country_id \
7263
ORDER BY s.id DESC \

src/main/webapp/WEB-INF/views/site/index.html

+11-36
Original file line numberDiff line numberDiff line change
@@ -134,81 +134,56 @@ <h4 class="panel-title" th:text="#{t_recently_added_series}">Recently added seri
134134
</div>
135135
<div class="panel-body" th:remove="all-but-first">
136136
<p th:each="series : ${recentlyAddedSeries}">
137-
<span th:if="${series.category != null}" th:remove="tag">
138-
<a href="../category/info.html" th:href="@{${INFO_CATEGORY_PAGE}(slug=${series.category.slug})}" th:text="${series.category.name}">Animals</a>&nbsp;&raquo;
139-
</span>
140-
141-
<span th:if="${series.country != null}" th:remove="tag">
142-
<a href="../country/info.html" th:href="@{${INFO_COUNTRY_PAGE}(slug=${series.country.slug})}" th:text="${series.country.name}">Italy</a>&nbsp;&raquo;
143-
</span>
144-
145137
<a href="../series/info.html" th:href="@{${INFO_SERIES_PAGE}(id=${series.id})}">
146-
<span th:remove="tag" th:if="${series.releaseYear != null}" th:text="|${series.releaseYear}, |">1999, </span>
138+
<span th:remove="tag"th:if="${series.country != null}" th:text="|${series.country}, |">Italy</span>
139+
<span th:remove="tag" th:if="${series.year != null}" th:text="|${series.year}, |">1999, </span>
147140
<span th:remove="tag" th:text="|${series.quantity}&nbsp;${series.quantity != 1 ? '__#{t_stamps}__' : '__#{t_stamp}__'}|">7&nbsp;stamps</span>
148141
<span th:remove="tag" th:if="${not series.perforated}" th:text="|(#{t_wo_perforation_short})|">(without perforation)</span>
149142
</a>
150143
</p>
151144
<p>
152-
<a href="../category/info.html">Animals</a>&nbsp;&raquo;
153-
<a href="../country/info.html">Italy</a>&nbsp;&raquo;
154145
<a href="../series/info.html">
155-
1997, 8&nbsp;stamps
146+
Italy, 1997, 8&nbsp;stamps
156147
</a>
157148
</p>
158149
<p>
159-
<a href="../category/info.html">Animals</a>&nbsp;&raquo;
160-
<a href="../country/info.html">Italy</a>&nbsp;&raquo;
161150
<a href="../series/info.html">
162-
2009, 10&nbsp;stamps
151+
Italy, 2009, 10&nbsp;stamps
163152
</a>
164153
</p>
165154
<p>
166-
<a href="../category/info.html">Animals</a>&nbsp;&raquo;
167-
<a href="../country/info.html">Italy</a>&nbsp;&raquo;
168155
<a href="../series/info.html">
169-
4&nbsp;stamps
156+
Italy, 4&nbsp;stamps
170157
</a>
171158
</p>
172159
<p>
173-
<a href="../category/info.html">Animals</a>&nbsp;&raquo;
174-
<a href="../country/info.html">Italy</a>&nbsp;&raquo;
175160
<a href="../series/info.html">
176-
2002, 12&nbsp;stamps
161+
Italy, 2002, 12&nbsp;stamps
177162
</a>
178163
</p>
179164
<p>
180-
<a href="../category/info.html">Animals</a>&nbsp;&raquo;
181-
<a href="../country/info.html">Italy</a>&nbsp;&raquo;
182165
<a href="../series/info.html">
183-
1993, 19&nbsp;stamps
166+
Italy, 1993, 19&nbsp;stamps
184167
</a>
185168
</p>
186169
<p>
187-
<a href="../category/info.html">Animals</a>&nbsp;&raquo;
188-
<a href="../country/info.html">Italy</a>&nbsp;&raquo;
189170
<a href="../series/info.html">
190-
4&nbsp;stamps
171+
Italy, 4&nbsp;stamps
191172
</a>
192173
</p>
193174
<p>
194-
<a href="../category/info.html">Animals</a>&nbsp;&raquo;
195-
<a href="../country/info.html">Italy</a>&nbsp;&raquo;
196175
<a href="../series/info.html">
197-
11&nbsp;stamps (without perforation)
176+
Italy, 11&nbsp;stamps (without perforation)
198177
</a>
199178
</p>
200179
<p>
201-
<a href="../category/info.html">Animals</a>&nbsp;&raquo;
202-
<a href="../country/info.html">Italy</a>&nbsp;&raquo;
203180
<a href="../series/info.html">
204-
2014, 1&nbsp;stamp
181+
Italy, 2014, 1&nbsp;stamp
205182
</a>
206183
</p>
207184
<p>
208-
<a href="../category/info.html">Animals</a>&nbsp;&raquo;
209-
<a href="../country/info.html">Italy</a>&nbsp;&raquo;
210185
<a href="../series/info.html">
211-
1996, 16&nbsp;stamps (without perforation)
186+
Italy, 1996, 16&nbsp;stamps (without perforation)
212187
</a>
213188
</p>
214189
</div>

0 commit comments

Comments
 (0)