Skip to content

Commit 5cc4ba8

Browse files
committed
CollectionDao.addSeriesToCollection(): replace argument collectionId by collectionSlug.
Addressed to #440 No functional changes.
1 parent 123fc21 commit 5cc4ba8

File tree

5 files changed

+16
-20
lines changed

5 files changed

+16
-20
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public interface CollectionDao {
3030
Integer add(AddCollectionDbDto collection);
3131
boolean isSeriesInUserCollection(Integer userId, Integer seriesId);
3232
UrlEntityDto findCollectionUrlEntityByUserId(Integer userId);
33-
void addSeriesToCollection(Integer collectionId, Integer seriesId);
33+
void addSeriesToCollection(String collectionSlug, Integer seriesId);
3434
void removeSeriesFromCollection(Integer collectionId, Integer seriesId);
3535
CollectionInfoDto findCollectionInfoBySlug(String slug);
3636
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,17 +138,17 @@ public UrlEntityDto findCollectionUrlEntityByUserId(Integer userId) {
138138
}
139139

140140
@Override
141-
public void addSeriesToCollection(Integer collectionId, Integer seriesId) {
141+
public void addSeriesToCollection(String collectionSlug, Integer seriesId) {
142142
Map<String, Object> params = new HashMap<>();
143-
params.put("collection_id", collectionId);
143+
params.put("collection_slug", collectionSlug);
144144
params.put("series_id", seriesId);
145145

146146
int affected = jdbcTemplate.update(addSeriesToCollectionSql, params);
147147
Validate.validState(
148148
affected == 1,
149-
"Unexpected number of affected rows after adding series #%d to collection #%d: %d",
149+
"Unexpected number of affected rows after adding series #%d to collection '%s': %d",
150150
seriesId,
151-
collectionId,
151+
collectionSlug,
152152
affected
153153
);
154154
}

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,13 @@ public UrlEntityDto addToCollection(Integer userId, Integer seriesId) {
7474
Validate.isTrue(seriesId != null, "Series id must be non null");
7575

7676
UrlEntityDto url = collectionDao.findCollectionUrlEntityByUserId(userId);
77-
Integer collectionId = url.getId();
77+
String collectionSlug = url.getSlug();
7878

79-
collectionDao.addSeriesToCollection(collectionId, seriesId);
79+
collectionDao.addSeriesToCollection(collectionSlug, seriesId);
8080

8181
LOG.info(
82-
"Series #{} has been added to collection #{} of user #{}",
82+
"Series #{} has been added to collection of user #{}",
8383
seriesId,
84-
collectionId,
8584
userId
8685
);
8786

src/main/resources/sql/collection_dao_queries.properties

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,11 @@ SELECT id, slug \
4545

4646
collection.add_series_to_collection = \
4747
INSERT \
48-
INTO collections_series \
49-
( collection_id \
50-
, series_id \
51-
) \
52-
VALUES \
53-
( :collection_id \
54-
, :series_id \
55-
)
48+
INTO collections_series(collection_id, series_id) \
49+
SELECT c.id AS collection_id \
50+
, :series_id AS series_id \
51+
FROM collections c \
52+
WHERE c.slug = :collection_slug
5653

5754
collection.remove_series_from_collection = \
5855
DELETE \

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,14 +122,14 @@ class CollectionServiceImplTest extends Specification {
122122
and:
123123
UrlEntityDto url = TestObjects.createUrlEntityDto()
124124
and:
125-
Integer expectedCollectionId = url.getId()
125+
String expectedCollectionSlug = url.getSlug()
126126
and:
127127
collectionDao.findCollectionUrlEntityByUserId(_ as Integer) >> url
128128
when:
129129
service.addToCollection(123, expectedSeriesId)
130130
then:
131-
1 * collectionDao.addSeriesToCollection({ Integer collectionId ->
132-
assert collectionId == expectedCollectionId
131+
1 * collectionDao.addSeriesToCollection({ String collectionSlug ->
132+
assert collectionSlug == expectedCollectionSlug
133133
return true
134134
}, { Integer seriesId ->
135135
assert seriesId == expectedSeriesId

0 commit comments

Comments
 (0)