Skip to content

Commit 1f15395

Browse files
committed
CategoryService.add(): change return type from UrlEntityDto to String.
Addressed to #440 No functional changes.
1 parent a36cbf1 commit 1f15395

File tree

4 files changed

+7
-12
lines changed

4 files changed

+7
-12
lines changed

src/main/java/ru/mystamps/web/controller/CategoryController.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
import ru.mystamps.web.controller.converter.annotation.CurrentUser;
4646
import ru.mystamps.web.dao.dto.LinkEntityDto;
4747
import ru.mystamps.web.dao.dto.SeriesInfoDto;
48-
import ru.mystamps.web.dao.dto.UrlEntityDto;
4948
import ru.mystamps.web.model.AddCategoryForm;
5049
import ru.mystamps.web.service.CategoryService;
5150
import ru.mystamps.web.service.SeriesService;
@@ -83,11 +82,11 @@ public String processInput(
8382
return null;
8483
}
8584

86-
UrlEntityDto categoryUrl = categoryService.add(form, currentUserId);
85+
String slug = categoryService.add(form, currentUserId);
8786

8887
redirectAttributes.addFlashAttribute("justAddedCategory", true);
8988

90-
return redirectTo(Url.INFO_CATEGORY_PAGE, categoryUrl.getSlug());
89+
return redirectTo(Url.INFO_CATEGORY_PAGE, slug);
9190
}
9291

9392
@RequestMapping(Url.INFO_CATEGORY_PAGE)

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,10 @@
2121
import java.util.List;
2222

2323
import ru.mystamps.web.dao.dto.LinkEntityDto;
24-
import ru.mystamps.web.dao.dto.UrlEntityDto;
2524
import ru.mystamps.web.service.dto.AddCategoryDto;
2625

2726
public interface CategoryService {
28-
UrlEntityDto add(AddCategoryDto dto, Integer userId);
27+
String add(AddCategoryDto dto, Integer userId);
2928
List<LinkEntityDto> findAllAsLinkEntities(String lang);
3029
LinkEntityDto findOneAsLinkEntity(String slug, String lang);
3130
long countAll();

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public class CategoryServiceImpl implements CategoryService {
5151
@Override
5252
@Transactional
5353
@PreAuthorize(HasAuthority.CREATE_CATEGORY)
54-
public UrlEntityDto add(AddCategoryDto dto, Integer userId) {
54+
public String add(AddCategoryDto dto, Integer userId) {
5555
Validate.isTrue(dto != null, "DTO must be non null");
5656
Validate.isTrue(dto.getName() != null, "Category name in English must be non null");
5757
Validate.isTrue(dto.getNameRu() != null, "Category name in Russian must be non null");
@@ -78,7 +78,7 @@ public UrlEntityDto add(AddCategoryDto dto, Integer userId) {
7878
Integer id = categoryDao.add(category);
7979
LOG.info("Category #{} has been created ({})", id, category);
8080

81-
return new UrlEntityDto(id, slug);
81+
return slug;
8282
}
8383

8484
@Override

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import ru.mystamps.web.dao.CategoryDao
2424
import ru.mystamps.web.dao.dto.AddCategoryDbDto
2525
import ru.mystamps.web.model.AddCategoryForm
2626
import ru.mystamps.web.dao.dto.LinkEntityDto
27-
import ru.mystamps.web.dao.dto.UrlEntityDto
2827
import ru.mystamps.web.tests.DateUtils
2928
import ru.mystamps.web.util.SlugUtils
3029

@@ -87,12 +86,10 @@ class CategoryServiceImplTest extends Specification {
8786
String expectedSlug = 'example-category'
8887
and:
8988
categoryDao.add(_ as AddCategoryDbDto) >> expectedId
90-
and:
91-
UrlEntityDto expected = new UrlEntityDto(expectedId, expectedSlug)
9289
when:
93-
UrlEntityDto actual = service.add(form, userId)
90+
String actualSlug = service.add(form, userId)
9491
then:
95-
actual == expected
92+
actualSlug == expectedSlug
9693
}
9794

9895
def "add() should pass English category name to dao"() {

0 commit comments

Comments
 (0)