Skip to content

Commit 0081e7a

Browse files
committed
Remove fixed currency values from database and show series info page.
Addressed to #778 No functional changes.
1 parent fd411b1 commit 0081e7a

File tree

11 files changed

+113
-66
lines changed

11 files changed

+113
-66
lines changed

src/main/java/ru/mystamps/web/controller/dto/AddSeriesForm.java

-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@
6161

6262
@Getter
6363
@Setter
64-
// TODO: combine price with currency to separate class
6564
@SuppressWarnings({ "PMD.TooManyFields", "PMD.AvoidDuplicateLiterals" })
6665
@RequireImageOrImageUrl(groups = AddSeriesForm.ImageUrl1Checks.class)
6766
@NotNullIfFirstField.List({

src/main/java/ru/mystamps/web/dao/dto/SeriesFullInfoDto.java

-9
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,10 @@ public class SeriesFullInfoDto {
3636
private final Boolean perforated;
3737
private final String comment;
3838
private final Integer createdBy;
39-
4039
private final BigDecimal michelPrice;
41-
private final String michelCurrency;
42-
4340
private final BigDecimal scottPrice;
44-
private final String scottCurrency;
45-
4641
private final BigDecimal yvertPrice;
47-
private final String yvertCurrency;
48-
4942
private final BigDecimal gibbonsPrice;
50-
private final String gibbonsCurrency;
51-
5243
private final BigDecimal solovyovPrice;
5344
private final BigDecimal zagorskiPrice;
5445
}

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

+4-16
Original file line numberDiff line numberDiff line change
@@ -121,18 +121,10 @@ public static SeriesFullInfoDto forSeriesFullInfoDto(ResultSet rs, int unused)
121121
String comment = rs.getString("comment");
122122
Integer createdBy = rs.getInt("created_by");
123123

124-
BigDecimal michelPrice = rs.getBigDecimal("michel_price");
125-
String michelCurrency = rs.getString("michel_currency");
126-
127-
BigDecimal scottPrice = rs.getBigDecimal("scott_price");
128-
String scottCurrency = rs.getString("scott_currency");
129-
130-
BigDecimal yvertPrice = rs.getBigDecimal("yvert_price");
131-
String yvertCurrency = rs.getString("yvert_currency");
132-
133-
BigDecimal gibbonsPrice = rs.getBigDecimal("gibbons_price");
134-
String gibbonsCurrency = rs.getString("gibbons_currency");
135-
124+
BigDecimal michelPrice = rs.getBigDecimal("michel_price");
125+
BigDecimal scottPrice = rs.getBigDecimal("scott_price");
126+
BigDecimal yvertPrice = rs.getBigDecimal("yvert_price");
127+
BigDecimal gibbonsPrice = rs.getBigDecimal("gibbons_price");
136128
BigDecimal solovyovPrice = rs.getBigDecimal("solovyov_price");
137129
BigDecimal zagorskiPrice = rs.getBigDecimal("zagorski_price");
138130

@@ -154,13 +146,9 @@ public static SeriesFullInfoDto forSeriesFullInfoDto(ResultSet rs, int unused)
154146
comment,
155147
createdBy,
156148
michelPrice,
157-
michelCurrency,
158149
scottPrice,
159-
scottCurrency,
160150
yvertPrice,
161-
yvertCurrency,
162151
gibbonsPrice,
163-
gibbonsCurrency,
164152
solovyovPrice,
165153
zagorskiPrice
166154
);

src/main/java/ru/mystamps/web/service/dto/CatalogInfoDto.java

+2-9
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,13 @@
2424
import java.util.Locale;
2525

2626
import lombok.Getter;
27-
28-
import ru.mystamps.web.dao.dto.Currency;
27+
import lombok.RequiredArgsConstructor;
2928

3029
@Getter
30+
@RequiredArgsConstructor
3131
public class CatalogInfoDto {
3232
private final List<String> numbers;
3333
private final BigDecimal price;
34-
private final Currency currency;
35-
36-
public CatalogInfoDto(List<String> numbers, BigDecimal price, String currency) {
37-
this.numbers = numbers;
38-
this.price = price;
39-
this.currency = currency == null ? null : Currency.valueOf(currency);
40-
}
4134

4235
// used to emulate <fmt:formatNumber pattern="###.##" />
4336
public String getFormattedPrice() {

src/main/java/ru/mystamps/web/service/dto/SeriesDto.java

+6-7
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,12 @@ public SeriesDto(
6060
List<Integer> imageIds) {
6161

6262
this.info = info;
63-
// CheckStyle: ignore LineLength for next 6 lines
64-
this.michel = new CatalogInfoDto(michelNumbers, info.getMichelPrice(), info.getMichelCurrency());
65-
this.scott = new CatalogInfoDto(scottNumbers, info.getScottPrice(), info.getScottCurrency());
66-
this.yvert = new CatalogInfoDto(yvertNumbers, info.getYvertPrice(), info.getYvertCurrency());
67-
this.gibbons = new CatalogInfoDto(gibbonsNumbers, info.getGibbonsPrice(), info.getGibbonsCurrency());
68-
this.solovyov = new CatalogInfoDto(solovyovNumbers, info.getSolovyovPrice(), null /* unused field currency */);
69-
this.zagorski = new CatalogInfoDto(zagorskiNumbers, info.getZagorskiPrice(), null /* unused field currency */);
63+
this.michel = new CatalogInfoDto(michelNumbers, info.getMichelPrice());
64+
this.scott = new CatalogInfoDto(scottNumbers, info.getScottPrice());
65+
this.yvert = new CatalogInfoDto(yvertNumbers, info.getYvertPrice());
66+
this.gibbons = new CatalogInfoDto(gibbonsNumbers, info.getGibbonsPrice());
67+
this.solovyov = new CatalogInfoDto(solovyovNumbers, info.getSolovyovPrice());
68+
this.zagorski = new CatalogInfoDto(zagorskiNumbers, info.getZagorskiPrice());
7069
this.imageIds = imageIds;
7170
}
7271

src/main/resources/liquibase/version/0.4.xml

+1
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,6 @@
4848
<include file="0.4/2018-01-01--add_perforated_to_parsed_data.xml" relativeToChangelogFile="true" />
4949
<include file="0.4/2018-01-04--series_sales_import_parsed_data.xml" relativeToChangelogFile="true" />
5050
<include file="0.4/2018-02-09--add_seller_info_to_parsed_data.xml" relativeToChangelogFile="true" />
51+
<include file="0.4/2018-03-11--series_remove_currency_fields.xml" relativeToChangelogFile="true" />
5152

5253
</databaseChangeLog>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<databaseChangeLog
3+
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
6+
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd">
7+
8+
<changeSet id="drop-michel_currency-column-from-series-table" author="php-coder" context="scheme">
9+
10+
<preConditions>
11+
<sqlCheck expectedResult="0">
12+
SELECT COUNT(*)
13+
FROM series
14+
WHERE michel_currency IS NOT NULL
15+
AND michel_currency != 'EUR'
16+
</sqlCheck>
17+
</preConditions>
18+
19+
<dropColumn tableName="series" columnName="michel_currency" />
20+
21+
<rollback>
22+
<addColumn tableName="series">
23+
<column name="michel_currency" type="VARCHAR(3)" afterColumn="michel_price" />
24+
</addColumn>
25+
</rollback>
26+
27+
</changeSet>
28+
29+
<changeSet id="drop-scott_currency-column-from-series-table" author="php-coder" context="scheme">
30+
31+
<preConditions>
32+
<sqlCheck expectedResult="0">
33+
SELECT COUNT(*)
34+
FROM series
35+
WHERE scott_currency IS NOT NULL
36+
AND scott_currency != 'USD'
37+
</sqlCheck>
38+
</preConditions>
39+
40+
<dropColumn tableName="series" columnName="scott_currency" />
41+
42+
<rollback>
43+
<addColumn tableName="series">
44+
<column name="scott_currency" type="VARCHAR(3)" afterColumn="scott_price" />
45+
</addColumn>
46+
</rollback>
47+
48+
</changeSet>
49+
50+
<changeSet id="drop-gibbons_currency-column-from-series-table" author="php-coder" context="scheme">
51+
52+
<preConditions>
53+
<sqlCheck expectedResult="0">
54+
SELECT COUNT(*)
55+
FROM series
56+
WHERE gibbons_currency IS NOT NULL
57+
AND gibbons_currency != 'GBP'
58+
</sqlCheck>
59+
</preConditions>
60+
61+
<dropColumn tableName="series" columnName="gibbons_currency" />
62+
63+
<rollback>
64+
<addColumn tableName="series">
65+
<column name="gibbons_currency" type="VARCHAR(3)" afterColumn="gibbons_price" />
66+
</addColumn>
67+
</rollback>
68+
69+
</changeSet>
70+
71+
<changeSet id="drop-yvert_currency-column-from-series-table" author="php-coder" context="scheme">
72+
73+
<preConditions>
74+
<sqlCheck expectedResult="0">
75+
SELECT COUNT(*)
76+
FROM series
77+
WHERE yvert_currency IS NOT NULL
78+
AND yvert_currency != 'EUR'
79+
</sqlCheck>
80+
</preConditions>
81+
82+
<dropColumn tableName="series" columnName="yvert_currency" />
83+
84+
<rollback>
85+
<addColumn tableName="series">
86+
<column name="yvert_currency" type="VARCHAR(3)" afterColumn="yvert_price" />
87+
</addColumn>
88+
</rollback>
89+
90+
</changeSet>
91+
92+
</databaseChangeLog>

src/main/resources/sql/series_dao_queries.properties

-12
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,9 @@ INSERT \
99
, release_month \
1010
, release_year \
1111
, michel_price \
12-
, michel_currency \
1312
, scott_price \
14-
, scott_currency \
1513
, yvert_price \
16-
, yvert_currency \
1714
, gibbons_price \
18-
, gibbons_currency \
1915
, solovyov_price \
2016
, zagorski_price \
2117
, comment \
@@ -33,13 +29,9 @@ VALUES \
3329
, :release_month \
3430
, :release_year \
3531
, :michel_price \
36-
, 'EUR' \
3732
, :scott_price \
38-
, 'USD' \
3933
, :yvert_price \
40-
, 'EUR' \
4134
, :gibbons_price \
42-
, 'GBP' \
4335
, :solovyov_price \
4436
, :zagorski_price \
4537
, :comment \
@@ -94,13 +86,9 @@ series.find_full_info_by_id = \
9486
, s.quantity \
9587
, s.perforated \
9688
, s.michel_price \
97-
, s.michel_currency \
9889
, s.scott_price \
99-
, s.scott_currency \
10090
, s.yvert_price \
101-
, s.yvert_currency \
10291
, s.gibbons_price \
103-
, s.gibbons_currency \
10492
, s.solovyov_price \
10593
, s.zagorski_price \
10694
, s.comment \

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@
219219
</span>
220220
<span th:if="${showPrice}"
221221
th:with="showBrackets=${showNumbers and showPrice}"
222-
th:text="${showBrackets ? '(' : ''} + ${series.michel.formattedPrice} + ' ' + ${series.michel.currency} + ${showBrackets ? ')' : ''}"
222+
th:text="${showBrackets ? '(' : ''} + ${series.michel.formattedPrice} + ' EUR' +${showBrackets ? ')' : ''}"
223223
th:remove="tag">
224224
(10 EUR)
225225
</span>
@@ -235,7 +235,7 @@
235235
<span th:if="${showNumbers}" th:text="|#${scottNumbers}|" th:remove="tag"></span>
236236
<span th:if="${showPrice}"
237237
th:with="price=${#numbers.formatDecimal(series.scott.price, 1, 1)},showBrackets=${showNumbers and showPrice}"
238-
th:text="${showBrackets ? '(' : ''} + ${series.scott.formattedPrice} + ' ' + ${series.scott.currency} + ${showBrackets ? ')' : ''}"
238+
th:text="${showBrackets ? '(' : ''} + ${series.scott.formattedPrice} + ' USD' + ${showBrackets ? ')' : ''}"
239239
th:remove="tag">
240240
12 USD
241241
</span>
@@ -253,7 +253,7 @@
253253
</span>
254254
<span th:if="${showPrice}"
255255
th:with="showBrackets=${showNumbers and showPrice}"
256-
th:text="${showBrackets ? '(' : ''} + ${series.yvert.formattedPrice} + ' ' + ${series.yvert.currency} + ${showBrackets ? ')' : ''}"
256+
th:text="${showBrackets ? '(' : ''} + ${series.yvert.formattedPrice} + ' EUR' + ${showBrackets ? ')' : ''}"
257257
th:remove="tag">
258258
(7 EUR)
259259
</span>
@@ -271,7 +271,7 @@
271271
</span>
272272
<span th:if="${showPrice}"
273273
th:with="showBrackets=${showNumbers and showPrice}"
274-
th:text="${showBrackets ? '(' : ''} + ${series.gibbons.formattedPrice} + ' ' + ${series.gibbons.currency} + ${showBrackets ? ')' : ''}"
274+
th:text="${showBrackets ? '(' : ''} + ${series.gibbons.formattedPrice} + ' GBP' + ${showBrackets ? ')' : ''}"
275275
th:remove="tag">
276276
</span>
277277
</dd>

src/test/groovy/ru/mystamps/web/service/SeriesServiceImplTest.groovy

-4
Original file line numberDiff line numberDiff line change
@@ -765,19 +765,15 @@ class SeriesServiceImplTest extends Specification {
765765

766766
result.michel?.numbers == expectedMichelNumbers
767767
result.michel?.price == expectedInfo.michelPrice
768-
result.michel?.currency == Currency.valueOf(expectedInfo.michelCurrency)
769768

770769
result.scott?.numbers == expectedScottNumbers
771770
result.scott?.price == expectedInfo.scottPrice
772-
result.scott?.currency == Currency.valueOf(expectedInfo.scottCurrency)
773771

774772
result.yvert?.numbers == expectedYvertNumbers
775773
result.yvert?.price == expectedInfo.yvertPrice
776-
result.yvert?.currency == Currency.valueOf(expectedInfo.yvertCurrency)
777774

778775
result.gibbons?.numbers == expectedGibbonsNumbers
779776
result.gibbons?.price == expectedInfo.gibbonsPrice
780-
result.gibbons?.currency == Currency.valueOf(expectedInfo.gibbonsCurrency)
781777

782778
result.solovyov?.numbers == expectedSolovyovNumbers
783779
result.solovyov?.price == expectedInfo.solovyovPrice

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,10 @@ public static SeriesFullInfoDto createSeriesFullInfoDto() {
144144
info.getPerforated(),
145145
"this is a full info",
146146
Random.userId(),
147-
TEST_PRICE, Currency.EUR.toString(),
148-
TEST_PRICE, Currency.USD.toString(),
149-
TEST_PRICE, Currency.EUR.toString(),
150-
TEST_PRICE, Currency.GBP.toString(),
147+
TEST_PRICE,
148+
TEST_PRICE,
149+
TEST_PRICE,
150+
TEST_PRICE,
151151
Random.price(),
152152
Random.price()
153153
);

0 commit comments

Comments
 (0)