Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

카테고리 목록 조회시, 카테고리가 없으면 404 에러 발생 #149

Merged
merged 1 commit into from
Jun 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,10 @@ public Category findCategoryWithUser(Long id, Long userId) {
}

public List<CategoryDto> categoriesOf(Long userId) {
UserJpaEntity user = findUser(userId);
List<CategoryDto> categories = categoryRepository.findCategoriesByUserOrderBySequence(user)
.stream().map(this::buildCategoryDto).collect(
Collectors.toList());
validateExistAtLeastOneCategory(categories);

return categories;
return categoryRepository.findCategoriesByUserOrderBySequence(findUser(userId))
akalswl14 marked this conversation as resolved.
Show resolved Hide resolved
.stream()
.map(this::buildCategoryDto)
.collect(Collectors.toList());
}

@Transactional
Expand Down Expand Up @@ -110,12 +107,6 @@ private int getSequence(UserJpaEntity user) {
return categoryRepository.countCategoriesByUser(user);
}

private void validateExistAtLeastOneCategory(List<CategoryDto> categories) {
akalswl14 marked this conversation as resolved.
Show resolved Hide resolved
if (categories.size() == 0) {
throw new CategoryNotFoundException();
}
}

private void validateDuplicateCategory(String name, UserJpaEntity user) {
List<CategoryDto> categories = categoryRepository.findCategoryDto(user);
long count = categories.stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,9 @@ private Category findCategory(Long id) {
}

@Test
public void categoriesOf_카테고리가_하나도_존재하지_않으면_예외를_발생한다() throws Exception {
assertThatThrownBy(() -> {
categoryService.categoriesOf(findUser("1").getId());
}).isInstanceOf(CategoryNotFoundException.class);
public void categoriesOf_카테고리가_하나도_존재하지_않는다면_빈_리스트를_반환한다() throws Exception {
akalswl14 marked this conversation as resolved.
Show resolved Hide resolved
List<CategoryDto> actual = categoryService.categoriesOf(findUser("1").getId());
assertThat(actual.size()).isEqualTo(0);
}

@Test
Expand Down