Skip to content

Commit 04a8240

Browse files
committed
JdbcCollectionDao.add(): use DTO instead of entity as argument.
Addressed to #120 No functional changes.
1 parent 220c20e commit 04a8240

File tree

4 files changed

+40
-10
lines changed

4 files changed

+40
-10
lines changed

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717
*/
1818
package ru.mystamps.web.dao;
1919

20-
import ru.mystamps.web.entity.Collection;
20+
import ru.mystamps.web.dao.dto.AddCollectionDbDto;
2121
import ru.mystamps.web.service.dto.LinkEntityDto;
2222

2323
public interface JdbcCollectionDao {
2424
Iterable<LinkEntityDto> findLastCreated(int quantity);
2525
long countCollectionsOfUsers();
26-
Integer add(Collection collection);
26+
Integer add(AddCollectionDbDto collection);
2727
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright (C) 2009-2015 Slava Semushin <[email protected]>
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.dao.dto;
19+
20+
import lombok.Getter;
21+
import lombok.Setter;
22+
import lombok.ToString;
23+
24+
@Getter
25+
@Setter
26+
@ToString
27+
public class AddCollectionDbDto {
28+
private Integer ownerId;
29+
private String slug;
30+
}

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
import lombok.RequiredArgsConstructor;
3333

3434
import ru.mystamps.web.dao.JdbcCollectionDao;
35-
import ru.mystamps.web.entity.Collection;
35+
import ru.mystamps.web.dao.dto.AddCollectionDbDto;
3636
import ru.mystamps.web.service.dto.LinkEntityDto;
3737

3838
@RequiredArgsConstructor
@@ -68,9 +68,9 @@ public long countCollectionsOfUsers() {
6868
}
6969

7070
@Override
71-
public Integer add(Collection collection) {
71+
public Integer add(AddCollectionDbDto collection) {
7272
Map<String, Object> params = new HashMap<>();
73-
params.put("user_id", collection.getOwner().getId());
73+
params.put("user_id", collection.getOwnerId());
7474
params.put("slug", collection.getSlug());
7575

7676
KeyHolder holder = new GeneratedKeyHolder();

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
import ru.mystamps.web.dao.CollectionDao;
3131
import ru.mystamps.web.dao.JdbcCollectionDao;
32+
import ru.mystamps.web.dao.dto.AddCollectionDbDto;
3233
import ru.mystamps.web.entity.Collection;
3334
import ru.mystamps.web.entity.Series;
3435
import ru.mystamps.web.entity.User;
@@ -47,17 +48,16 @@ public class CollectionServiceImpl implements CollectionService {
4748
public void createCollection(User user) {
4849
Validate.isTrue(user != null, "User must be non null");
4950

50-
Collection collection = new Collection();
51-
collection.setOwner(user);
51+
AddCollectionDbDto collection = new AddCollectionDbDto();
52+
collection.setOwnerId(user.getId());
5253

5354
String slug = SlugUtils.slugify(user.getLogin());
5455
Validate.isTrue(slug != null, "Slug for string '%s' is null", user.getLogin());
5556
collection.setSlug(slug);
5657

57-
Integer collectionId = jdbcCollectionDao.add(collection);
58-
collection.setId(collectionId);
58+
Integer id = jdbcCollectionDao.add(collection);
5959

60-
LOG.info("Collection has been created ({})", collection);
60+
LOG.info("Collection #{} has been created ({})", id, collection);
6161
}
6262

6363
@Override

0 commit comments

Comments
 (0)