Skip to content

Commit 07ff2c7

Browse files
committed
refactor: move dao/service/mapper methods that work with PurchaseAndSaleDto to ru.mystamps.web.feature.series.sale package.
Part of #1051
1 parent 8487a12 commit 07ff2c7

File tree

13 files changed

+141
-97
lines changed

13 files changed

+141
-97
lines changed

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

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@
3737
@SuppressWarnings({
3838
"PMD.AvoidDuplicateLiterals",
3939
"PMD.TooManyMethods",
40-
"PMD.TooManyFields",
41-
"PMD.LongVariable"
40+
"PMD.TooManyFields"
4241
})
4342
@RequiredArgsConstructor
4443
public class JdbcSeriesDao implements SeriesDao {
@@ -78,9 +77,6 @@ public class JdbcSeriesDao implements SeriesDao {
7877
@Value("${series.find_by_country_slug}")
7978
private String findByCountrySlugSql;
8079

81-
@Value("${series_sales.find_sales_by_series_id}")
82-
private String findPurchasesAndSalesBySeriesIdSql;
83-
8480
@Value("${series.count_all_series}")
8581
private String countAllSql;
8682

@@ -290,18 +286,6 @@ public List<SeriesInGalleryDto> findByCountrySlug(String slug, String lang) {
290286
return jdbcTemplate.query(findByCountrySlugSql, params, RowMappers::forSeriesInGalleryDto);
291287
}
292288

293-
/**
294-
* @author Sergey Chechenev
295-
*/
296-
@Override
297-
public List<PurchaseAndSaleDto> findPurchasesAndSales(Integer seriesId) {
298-
return jdbcTemplate.query(
299-
findPurchasesAndSalesBySeriesIdSql,
300-
Collections.singletonMap("series_id", seriesId),
301-
RowMappers::forPurchaseAndSaleDto
302-
);
303-
}
304-
305289
@Override
306290
public long countAll() {
307291
return jdbcTemplate.queryForObject(countAllSql, Collections.emptyMap(), Long.class);

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

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,12 @@
1717
*/
1818
package ru.mystamps.web.feature.series;
1919

20-
import ru.mystamps.web.common.Currency;
2120
import ru.mystamps.web.common.JdbcUtils;
2221
import ru.mystamps.web.common.LinkEntityDto;
23-
import ru.mystamps.web.feature.series.sale.SeriesCondition;
2422

2523
import java.math.BigDecimal;
2624
import java.sql.ResultSet;
2725
import java.sql.SQLException;
28-
import java.util.Date;
2926

3027
import static ru.mystamps.web.common.RowMappers.createLinkEntityDto;
3128

@@ -99,42 +96,6 @@ private RowMappers() {
9996
category
10097
);
10198
}
102-
103-
/**
104-
* @author Sergey Chechenev
105-
*/
106-
/* default */ static PurchaseAndSaleDto forPurchaseAndSaleDto(ResultSet rs, int unused)
107-
throws SQLException {
108-
109-
Date date = rs.getDate("date");
110-
String sellerName = rs.getString("seller_name");
111-
String sellerUrl = rs.getString("seller_url");
112-
String buyerName = rs.getString("buyer_name");
113-
String buyerUrl = rs.getString("buyer_url");
114-
String transactionUrl = rs.getString("transaction_url");
115-
BigDecimal firstPrice = rs.getBigDecimal("first_price");
116-
Currency firstCurrency = JdbcUtils.getCurrency(rs, "first_currency");
117-
BigDecimal secondPrice = rs.getBigDecimal("second_price");
118-
Currency secondCurrency = JdbcUtils.getCurrency(rs, "second_currency");
119-
120-
// LATER: consider extracting this into a helper method
121-
String conditionField = rs.getString("cond");
122-
SeriesCondition condition = rs.wasNull() ? null : SeriesCondition.valueOf(conditionField);
123-
124-
return new PurchaseAndSaleDto(
125-
date,
126-
sellerName,
127-
sellerUrl,
128-
buyerName,
129-
buyerUrl,
130-
transactionUrl,
131-
firstPrice,
132-
firstCurrency,
133-
secondPrice,
134-
secondCurrency,
135-
condition
136-
);
137-
}
13899

139100
/* default */ static SeriesFullInfoDto forSeriesFullInfoDto(ResultSet rs, int unused)
140101
throws SQLException {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,7 @@ public static void loadErrorsFromDownloadInterceptor(
749749

750750
if (SecurityContextUtils.hasAuthority(Authority.VIEW_SERIES_SALES)) {
751751
List<PurchaseAndSaleDto> purchasesAndSales =
752-
seriesService.findPurchasesAndSales(seriesId);
752+
seriesSalesService.findSales(seriesId);
753753
model.put("purchasesAndSales", purchasesAndSales);
754754
}
755755

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ public interface SeriesDao {
3434
List<SeriesInfoDto> findByIdsAsSeriesInfo(List<Integer> seriesIds, String lang);
3535
List<SeriesInfoDto> findByCategorySlugAsSeriesInfo(String slug, String lang);
3636
List<SeriesInGalleryDto> findByCountrySlug(String slug, String lang);
37-
List<PurchaseAndSaleDto> findPurchasesAndSales(Integer seriesId);
3837

3938
long countAll();
4039
long countAllStamps();

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,5 @@ public interface SeriesService {
5353
List<SeriesLinkDto> findSimilarSeries(Integer seriesId, String lang);
5454
List<SitemapInfoDto> findAllForSitemap();
5555

56-
List<PurchaseAndSaleDto> findPurchasesAndSales(Integer seriesId);
57-
5856
void markAsSimilar(AddSimilarSeriesForm dto);
5957
}

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

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -418,18 +418,6 @@ public List<SitemapInfoDto> findAllForSitemap() {
418418
return seriesDao.findAllForSitemap();
419419
}
420420

421-
/**
422-
* @author Sergey Chechenev
423-
*/
424-
@Override
425-
@Transactional(readOnly = true)
426-
@PreAuthorize(HasAuthority.VIEW_SERIES_SALES)
427-
public List<PurchaseAndSaleDto> findPurchasesAndSales(Integer seriesId) {
428-
Validate.isTrue(seriesId != null, "Series id must be non null");
429-
430-
return seriesDao.findPurchasesAndSales(seriesId);
431-
}
432-
433421
// @todo #1280 SeriesServiceImpl.markAsSimilar(): add unit tests
434422
@Override
435423
@Transactional

src/main/java/ru/mystamps/web/feature/series/sale/JdbcSeriesSalesDao.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,11 @@
2121
import org.apache.commons.lang3.Validate;
2222
import org.springframework.beans.factory.annotation.Value;
2323
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
24+
import ru.mystamps.web.feature.series.PurchaseAndSaleDto;
2425

26+
import java.util.Collections;
2527
import java.util.HashMap;
28+
import java.util.List;
2629
import java.util.Map;
2730

2831
@RequiredArgsConstructor
@@ -33,6 +36,9 @@ public class JdbcSeriesSalesDao implements SeriesSalesDao {
3336
@Value("${series_sales.add}")
3437
private String addSeriesSaleSql;
3538

39+
@Value("${series_sales.find_sales_by_series_id}")
40+
private String findSeriesSalesBySeriesIdSql;
41+
3642
@Override
3743
public void add(AddSeriesSalesDbDto sale) {
3844
Map<String, Object> params = new HashMap<>();
@@ -58,4 +64,16 @@ public void add(AddSeriesSalesDbDto sale) {
5864
);
5965
}
6066

67+
/**
68+
* @author Sergey Chechenev
69+
*/
70+
@Override
71+
public List<PurchaseAndSaleDto> findSeriesSales(Integer seriesId) {
72+
return jdbcTemplate.query(
73+
findSeriesSalesBySeriesIdSql,
74+
Collections.singletonMap("series_id", seriesId),
75+
RowMappers::forPurchaseAndSaleDto
76+
);
77+
}
78+
6179
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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.sale;
19+
20+
import ru.mystamps.web.common.Currency;
21+
import ru.mystamps.web.common.JdbcUtils;
22+
import ru.mystamps.web.feature.series.PurchaseAndSaleDto;
23+
24+
import java.math.BigDecimal;
25+
import java.sql.ResultSet;
26+
import java.sql.SQLException;
27+
import java.util.Date;
28+
29+
final class RowMappers {
30+
31+
private RowMappers() {
32+
}
33+
34+
/**
35+
* @author Sergey Chechenev
36+
*/
37+
/* default */ static PurchaseAndSaleDto forPurchaseAndSaleDto(ResultSet rs, int unused)
38+
throws SQLException {
39+
40+
Date date = rs.getDate("date");
41+
String sellerName = rs.getString("seller_name");
42+
String sellerUrl = rs.getString("seller_url");
43+
String buyerName = rs.getString("buyer_name");
44+
String buyerUrl = rs.getString("buyer_url");
45+
String transactionUrl = rs.getString("transaction_url");
46+
BigDecimal firstPrice = rs.getBigDecimal("first_price");
47+
Currency firstCurrency = JdbcUtils.getCurrency(rs, "first_currency");
48+
BigDecimal secondPrice = rs.getBigDecimal("second_price");
49+
Currency secondCurrency = JdbcUtils.getCurrency(rs, "second_currency");
50+
51+
// LATER: consider extracting this into a helper method
52+
String conditionField = rs.getString("cond");
53+
SeriesCondition condition = rs.wasNull() ? null : SeriesCondition.valueOf(conditionField);
54+
55+
return new PurchaseAndSaleDto(
56+
date,
57+
sellerName,
58+
sellerUrl,
59+
buyerName,
60+
buyerUrl,
61+
transactionUrl,
62+
firstPrice,
63+
firstCurrency,
64+
secondPrice,
65+
secondCurrency,
66+
condition
67+
);
68+
}
69+
70+
}

src/main/java/ru/mystamps/web/feature/series/sale/SeriesSalesDao.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@
1717
*/
1818
package ru.mystamps.web.feature.series.sale;
1919

20+
import ru.mystamps.web.feature.series.PurchaseAndSaleDto;
21+
22+
import java.util.List;
23+
2024
public interface SeriesSalesDao {
2125
void add(AddSeriesSalesDbDto dto);
26+
List<PurchaseAndSaleDto> findSeriesSales(Integer seriesId);
2227
}

src/main/java/ru/mystamps/web/feature/series/sale/SeriesSalesService.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@
1717
*/
1818
package ru.mystamps.web.feature.series.sale;
1919

20+
import ru.mystamps.web.feature.series.PurchaseAndSaleDto;
21+
22+
import java.util.List;
23+
2024
public interface SeriesSalesService {
2125
void add(AddSeriesSalesDto dto, Integer seriesId, Integer userId);
26+
List<PurchaseAndSaleDto> findSales(Integer seriesId);
2227
}

0 commit comments

Comments
 (0)