Skip to content

Commit fc7e116

Browse files
committed
User can specify a price that he/she paid for a series.
Fix #663
1 parent 09fc76c commit fc7e116

File tree

13 files changed

+130
-3
lines changed

13 files changed

+130
-3
lines changed

NEWS.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
- (functionality) add support for specifying Solovyov catalog numbers
2222
- (functionality) add support for specifying Zagorski catalog numbers
2323
- (functionality) user may specify how many stamps from a series in his/her collection
24+
- (functionality) user may specify a price that he/she paid for a series
2425

2526
0.3
2627
- (functionality) implemented possibility to user to add series to his collection

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,24 @@
1717
*/
1818
package ru.mystamps.web.controller.dto;
1919

20+
import java.math.BigDecimal;
21+
2022
import javax.validation.constraints.Min;
2123
import javax.validation.constraints.NotNull;
2224

2325
import lombok.Getter;
2426
import lombok.Setter;
2527

28+
import ru.mystamps.web.dao.dto.Currency;
2629
import ru.mystamps.web.service.dto.AddToCollectionDto;
2730

2831
import static ru.mystamps.web.validation.ValidationRules.MIN_STAMPS_IN_SERIES;
2932

3033
// @todo #477 Add to collection: integration test for invisible quantity for a series with 1 stamp
3134
// @todo #477 Add to collection: series quantity should be specified by default
3235
// @todo #477 Add to collection: add integration test for custom number of stamps
36+
// @todo #663 Add to collection: add integration test for specifying a price
37+
// @todo #663 Add a page with a list of series, their prices and total cost
3338
@Getter
3439
@Setter
3540
public class AddToCollectionForm implements AddToCollectionDto {
@@ -39,4 +44,9 @@ public class AddToCollectionForm implements AddToCollectionDto {
3944
@Min(MIN_STAMPS_IN_SERIES)
4045
private Integer numberOfStamps;
4146

47+
// @todo #663 /series/{id}(price): must be greater than zero
48+
private BigDecimal price;
49+
50+
// @todo #663 /series/{id}(currency): must be required when price is specified
51+
private Currency currency;
4252
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
*/
1818
package ru.mystamps.web.dao.dto;
1919

20+
import java.math.BigDecimal;
21+
2022
import lombok.Getter;
2123
import lombok.Setter;
2224

@@ -26,4 +28,6 @@ public class AddToCollectionDbDto {
2628
private Integer ownerId;
2729
private Integer seriesId;
2830
private Integer numberOfStamps;
31+
private BigDecimal price;
32+
private String currency;
2933
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,8 @@ public void addSeriesToUserCollection(AddToCollectionDbDto dto) {
171171
params.put("user_id", dto.getOwnerId());
172172
params.put("series_id", dto.getSeriesId());
173173
params.put("number_of_stamps", dto.getNumberOfStamps());
174+
params.put("price", dto.getPrice());
175+
params.put("currency", dto.getCurrency());
174176

175177
int affected = jdbcTemplate.update(addSeriesToCollectionSql, params);
176178

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

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,24 @@ public void addToCollection(Integer userId, Integer seriesId, AddToCollectionDto
8282
collectionDto.setSeriesId(seriesId);
8383
collectionDto.setNumberOfStamps(dto.getNumberOfStamps());
8484

85+
if (dto.getPrice() != null) {
86+
Validate.validState(
87+
dto.getCurrency() != null,
88+
"Currency must be non null when price is specified"
89+
);
90+
collectionDto.setPrice(dto.getPrice());
91+
collectionDto.setCurrency(dto.getCurrency().toString());
92+
}
93+
8594
collectionDao.addSeriesToUserCollection(collectionDto);
8695
collectionDao.markAsModified(userId, new Date());
8796

88-
// TODO: it would be good to include number of stamps in series vs in collection
89-
log.info("Series #{} has been added to collection of user #{}", seriesId, userId);
97+
log.info(
98+
"Series #{} ({}) has been added to collection of user #{}",
99+
seriesId,
100+
formatSeriesInfo(collectionDto),
101+
userId
102+
);
90103
}
91104

92105
@Override
@@ -145,4 +158,21 @@ public CollectionInfoDto findBySlug(String slug) {
145158
return collectionDao.findCollectionInfoBySlug(slug);
146159
}
147160

161+
private static String formatSeriesInfo(AddToCollectionDbDto collectionDto) {
162+
StringBuilder sb = new StringBuilder();
163+
164+
// TODO: it would be good to include number of stamps in series vs in collection
165+
sb.append("stamps=")
166+
.append(collectionDto.getNumberOfStamps());
167+
168+
if (collectionDto.getPrice() != null) {
169+
sb.append(", price=")
170+
.append(collectionDto.getPrice())
171+
.append(' ')
172+
.append(collectionDto.getCurrency());
173+
}
174+
175+
return sb.toString();
176+
}
177+
148178
}

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

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

20+
import java.math.BigDecimal;
21+
22+
import ru.mystamps.web.dao.dto.Currency;
23+
2024
public interface AddToCollectionDto {
2125
Integer getNumberOfStamps();
26+
BigDecimal getPrice();
27+
Currency getCurrency();
2228
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,6 @@
5050
<include file="0.4/2018-02-09--add_seller_info_to_parsed_data.xml" relativeToChangelogFile="true" />
5151
<include file="0.4/2018-03-11--series_remove_currency_fields.xml" relativeToChangelogFile="true" />
5252
<include file="0.4/2018-06-09--add_number_of_stamps_to_collections_series.xml" relativeToChangelogFile="true" />
53+
<include file="0.4/2018-06-15--add_price_to_collections_series.xml" relativeToChangelogFile="true" />
5354

5455
</databaseChangeLog>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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="add-price-and-currency-fields-to-collections_series" author="php-coder" context="scheme">
9+
10+
<addColumn tableName="collections_series">
11+
<column name="price" type="DECIMAL(19,2)" />
12+
<column name="currency" type="CHAR(3)" />
13+
</addColumn>
14+
15+
</changeSet>
16+
17+
</databaseChangeLog>

src/main/resources/ru/mystamps/i18n/Messages.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ t_yes = Yes
136136
t_no = No
137137
t_series_not_in_collection = Series isn't part of your collection
138138
t_i_have = I have
139+
t_i_bought_for = I bought for
139140
t_out_of_n_stamps = out of {0} stamps
140141
t_series_in_collection = Series is part of your collection
141142
t_add_to_collection = Add to collection

src/main/resources/ru/mystamps/i18n/Messages_ru.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ t_yes = Да
135135
t_no = Нет
136136
t_series_not_in_collection = Этой серии нет в вашей коллекции
137137
t_i_have = У меня есть
138+
t_i_bought_for = Я купил за
138139
t_out_of_n_stamps = из {0} марок
139140
t_series_in_collection = Эта серия есть в вашей коллекции
140141
t_add_to_collection = Добавить в коллекцию

0 commit comments

Comments
 (0)