dto 매퍼 분리

This commit is contained in:
jinia91
2022-05-27 20:19:31 +09:00
parent b9a5196972
commit 05ddace884
4 changed files with 32 additions and 10 deletions

View File

@@ -26,10 +26,4 @@ public interface ArticleDtoMapper {
ArticleResponseForDetail detail(Article article);
ArticleResponseByCategory category(Article article);
TagsResponse of(Tags tag);
@Mappings({
@Mapping(target = "count",ignore = true),
@Mapping(target = "POrder",ignore = true),
@Mapping(target = "COrder",ignore = true)
})
CategorySimpleDto categorySimpleDto(Category category);
}

View File

@@ -0,0 +1,23 @@
package myblog.blog.category.appliacation;
import myblog.blog.article.application.port.incomming.response.*;
import myblog.blog.article.domain.Article;
import myblog.blog.article.domain.Tags;
import myblog.blog.category.appliacation.port.incomming.response.CategorySimpleDto;
import myblog.blog.category.domain.Category;
import org.mapstruct.*;
@Mapper(
componentModel = "spring",
injectionStrategy = InjectionStrategy.CONSTRUCTOR,
unmappedTargetPolicy = ReportingPolicy.ERROR
)
public interface CategoryDtoMapper {
ArticleResponseByCategory category(Article article);
@Mappings({
@Mapping(target = "count",ignore = true),
@Mapping(target = "POrder",ignore = true),
@Mapping(target = "COrder",ignore = true)
})
CategorySimpleDto categorySimpleDto(Category category);
}

View File

@@ -1,12 +1,10 @@
package myblog.blog.category.appliacation;
import lombok.RequiredArgsConstructor;
import myblog.blog.article.application.ArticleDtoMapper;
import myblog.blog.category.appliacation.port.incomming.CategoryQueriesUseCase;
import myblog.blog.category.appliacation.port.incomming.response.CategorySimpleDto;
import myblog.blog.category.appliacation.port.incomming.response.CategoryViewForLayout;
import myblog.blog.category.appliacation.port.outgoing.CategoryRepositoryPort;
import myblog.blog.shared.utils.MapperUtils;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -20,7 +18,7 @@ import java.util.stream.Collectors;
public class CategoryQueries implements CategoryQueriesUseCase {
private final CategoryRepositoryPort categoryRepositoryPort;
private final ArticleDtoMapper articleDtoMapper;
private final CategoryDtoMapper categoryDtoMapper;
/*
- 카테고리와 카테고리별 아티클 수 찾기
@@ -48,7 +46,7 @@ public class CategoryQueries implements CategoryQueriesUseCase {
public List<CategorySimpleDto> findCategoryByTier(int tier) {
return categoryRepositoryPort.findAllByTierIs(tier)
.stream()
.map(articleDtoMapper::categorySimpleDto)
.map(categoryDtoMapper::categorySimpleDto)
.collect(Collectors.toList());
}
}

View File

@@ -16,6 +16,8 @@ import org.junit.jupiter.api.extension.ExtendWith
import org.mockito.InjectMocks
import org.mockito.Mock
import org.mockito.junit.jupiter.MockitoExtension
import org.mockito.kotlin.times
import org.mockito.kotlin.verify
import org.mockito.kotlin.whenever
import java.util.*
import kotlin.test.assertFailsWith
@@ -63,5 +65,10 @@ class ArticleServiceTests {
sut.writeArticle(articleCreateCommand)
}
@Test
fun`article 삭제 성공`(){
sut.deleteArticle(1L)
verify(articleRepositoryPort, times(1)).deleteArticle(1L)
}
}