Skip to content

Commit f28665c

Browse files
committed
refactor(/collection/{slug}): rework representation of the links to the series.
No functional changes.
1 parent 58bc354 commit f28665c

File tree

4 files changed

+21
-65
lines changed

4 files changed

+21
-65
lines changed

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

+3-18
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import java.sql.SQLException;
2323

2424
import ru.mystamps.web.dao.dto.Currency;
25-
import ru.mystamps.web.dao.dto.LinkEntityDto;
2625
import ru.mystamps.web.support.jdbc.JdbcUtils;
2726

2827
final class RowMappers {
@@ -40,42 +39,28 @@ private RowMappers() {
4039
);
4140
}
4241

43-
// The only one difference from forSeriesInfoDto() is that
44-
// SeriesInCollectionDto has numberOfStamps member.
4542
/* default */ static SeriesInCollectionDto forSeriesInCollectionDto(ResultSet rs, int unused)
4643
throws SQLException {
4744

4845
Integer seriesId = rs.getInt("id");
46+
String category = rs.getString("category");
47+
String country = rs.getString("country");
4948
Integer releaseDay = JdbcUtils.getInteger(rs, "release_day");
5049
Integer releaseMonth = JdbcUtils.getInteger(rs, "release_month");
5150
Integer releaseYear = JdbcUtils.getInteger(rs, "release_year");
5251
Integer quantity = rs.getInt("quantity");
5352
Boolean perforated = rs.getBoolean("perforated");
5453
Integer numberOfStamps = rs.getInt("number_of_stamps");
5554

56-
LinkEntityDto category = ru.mystamps.web.support.jdbc.RowMappers.createLinkEntityDto(
57-
rs,
58-
"category_id",
59-
"category_slug",
60-
"category_name"
61-
);
62-
63-
LinkEntityDto country = ru.mystamps.web.support.jdbc.RowMappers.createLinkEntityDto(
64-
rs,
65-
"country_id",
66-
"country_slug",
67-
"country_name"
68-
);
69-
7055
return new SeriesInCollectionDto(
7156
seriesId,
7257
category,
7358
country,
7459
releaseDay,
7560
releaseMonth,
7661
releaseYear,
77-
quantity,
7862
perforated,
63+
quantity,
7964
numberOfStamps
8065
);
8166
}

src/main/java/ru/mystamps/web/feature/collection/SeriesInCollectionDto.java

+12-19
Original file line numberDiff line numberDiff line change
@@ -18,27 +18,20 @@
1818
package ru.mystamps.web.feature.collection;
1919

2020
import lombok.Getter;
21-
22-
import ru.mystamps.web.dao.dto.LinkEntityDto;
23-
import ru.mystamps.web.feature.series.SeriesInfoDto;
21+
import lombok.RequiredArgsConstructor;
2422

2523
@Getter
26-
public class SeriesInCollectionDto extends SeriesInfoDto {
27-
// SeriesInfoDto.quantity holds number of stamps in a series, while user may
24+
@RequiredArgsConstructor
25+
public class SeriesInCollectionDto {
26+
private final Integer id;
27+
private final String category;
28+
private final String country;
29+
private final Integer releaseDay;
30+
private final Integer releaseMonth;
31+
private final Integer releaseYear;
32+
private final Boolean perforated;
33+
private final Integer quantity;
34+
// quantity holds number of stamps in a series, while user may
2835
// have less stamps in his collection
2936
private final Integer numberOfStamps;
30-
31-
@SuppressWarnings("checkstyle:parameternumber")
32-
public SeriesInCollectionDto(
33-
Integer id,
34-
LinkEntityDto category,
35-
LinkEntityDto country,
36-
Integer releaseDay, Integer releaseMonth, Integer releaseYear,
37-
Integer quantity,
38-
Boolean perforated,
39-
Integer numberOfStamps) {
40-
super(id, category, country, releaseDay, releaseMonth, releaseYear, quantity, perforated);
41-
this.numberOfStamps = numberOfStamps;
42-
}
43-
4437
}

src/main/resources/sql/collection_dao_queries.properties

+2-6
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,8 @@ ORDER BY c.id DESC \
1212

1313
collection.find_series_by_collection_id = \
1414
SELECT s.id \
15-
, cat.id AS category_id \
16-
, cat.slug AS category_slug \
17-
, CASE WHEN 'ru' = :lang THEN COALESCE(cat.name_ru, cat.name) ELSE cat.name END AS category_name \
18-
, count.id AS country_id \
19-
, count.slug AS country_slug \
20-
, CASE WHEN 'ru' = :lang THEN COALESCE(count.name_ru, count.name) ELSE count.name END AS country_name \
15+
, CASE WHEN 'ru' = :lang THEN COALESCE(cat.name_ru, cat.name) ELSE cat.name END AS category \
16+
, CASE WHEN 'ru' = :lang THEN COALESCE(count.name_ru, count.name) ELSE count.name END AS country \
2117
, s.release_day \
2218
, s.release_month \
2319
, s.release_year \

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

+4-22
Original file line numberDiff line numberDiff line change
@@ -92,15 +92,9 @@ <h3 class="text-center" th:text="#{t_collection_of(${ownerName})}">
9292
<div class="col-sm-4">
9393
<ul th:if="${not #lists.isEmpty(seriesOfCollection)}" th:remove="all-but-first">
9494
<li th:each="series : ${seriesOfCollection}">
95-
<span th:if="${series.category != null}" th:remove="tag">
96-
<a href="../category/info.html" th:href="@{${INFO_CATEGORY_PAGE}(slug=${series.category.slug})}" th:text="${series.category.name}">Animals</a>&nbsp;&raquo;
97-
</span>
98-
99-
<span th:if="${series.country != null}" th:remove="tag">
100-
<a href="../country/info.html" th:href="@{${INFO_COUNTRY_PAGE}(slug=${series.country.slug})}" th:text="${series.country.name}">Italy</a>&nbsp;&raquo;
101-
</span>
102-
10395
<a href="../series/info.html" th:href="@{${INFO_SERIES_PAGE}(id=${series.id})}">
96+
<span th:remove="tag" th:text="|${series.category}, |">Animals, </span>
97+
<span th:remove="tag" th:if="${series.country != null}" th:text="|${series.country}, |">Italy, </span>
10498
<span th:remove="tag" th:if="${series.releaseYear != null}" th:text="|${series.releaseYear}, |">1999, </span>
10599
<span th:remove="tag" th:text="|${series.quantity}&nbsp;${series.quantity != 1 ? '__#{t_stamps}__' : '__#{t_stamp}__'}|">7&nbsp;stamps</span>
106100
<span th:remove="tag" th:if="${not series.perforated}" th:text="|(#{t_wo_perforation_short})|">(without perforation)</span>
@@ -113,23 +107,11 @@ <h3 class="text-center" th:text="#{t_collection_of(${ownerName})}">
113107
<span th:if="${justAddedSeriesId != null and justAddedSeriesId == series.id}" class="label label-success">New</span>
114108
</li>
115109
<li>
116-
<a href="../category/info.html">Animals</a>&nbsp;&raquo;
117-
118-
<a href="../country/info.html">Italy</a>&nbsp;&raquo;
119-
120-
<a href="../series/info.html">
121-
22&nbsp;stamps
122-
</a>
110+
<a href="../category/info.html">Animals, Italy, 22&nbsp;stamps</a>
123111
<span class="label label-default">20 out of 22</span>
124112
</li>
125113
<li>
126-
<a href="../category/info.html">Animals</a>&nbsp;&raquo;
127-
128-
<a href="../country/info.html">Italy</a>&nbsp;&raquo;
129-
130-
<a href="../series/info.html">
131-
1983, 5&nbsp;stamps
132-
</a>
114+
<a href="../category/info.html">Animals, Italy, 1983, 5&nbsp;stamps</a>
133115
</li>
134116
</ul>
135117
</div>

0 commit comments

Comments
 (0)