modelmapper 불필요한 스프링 의존성 제거, 스레드 세이프한 객체이므로 static final로 상태를 가져도 안전

This commit is contained in:
jinia91
2022-03-27 01:16:39 +09:00
parent 2c480220ac
commit a1e80852d4
3 changed files with 11 additions and 25 deletions

View File

@@ -13,7 +13,7 @@ import myblog.blog.article.application.port.incomming.response.ArticleResponseBy
import myblog.blog.article.application.port.incomming.response.ArticleResponseForDetail;
import myblog.blog.article.application.port.incomming.response.ArticleResponseForEdit;
import org.modelmapper.ModelMapper;
import myblog.blog.shared.utils.MapperUtils;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
@@ -28,7 +28,6 @@ public class ArticleQueries implements ArticleQueriesUseCase {
private final ArticleRepositoryPort articleRepositoryPort;
private final CategoryUseCase categoryUseCase;
private final ModelMapper modelMapper;
/*
- 메인화면 위한 인기 아티클 6개 목록 가져오기
@@ -41,7 +40,7 @@ public class ArticleQueries implements ArticleQueriesUseCase {
public List<ArticleResponseForCardBox> getPopularArticles() {
return articleRepositoryPort.findTop6ByOrderByHitDesc()
.stream()
.map(article -> modelMapper.map(article, ArticleResponseForCardBox.class))
.map(article -> MapperUtils.getModelMapper().map(article, ArticleResponseForCardBox.class))
.collect(Collectors.toList());
}
/*
@@ -60,7 +59,7 @@ public class ArticleQueries implements ArticleQueriesUseCase {
.findByOrderByIdDesc(lastArticleId, PageRequest.of(0, 5));
return articles
.stream()
.map(article -> modelMapper.map(article, ArticleResponseForCardBox.class))
.map(article -> MapperUtils.getModelMapper().map(article, ArticleResponseForCardBox.class))
.collect(Collectors.toList());
}
/*
@@ -89,7 +88,7 @@ public class ArticleQueries implements ArticleQueriesUseCase {
if(articles == null) throw new IllegalArgumentException("NotFoundArticleException");
return articles.map(article -> modelMapper.map(article, ArticleResponseForCardBox.class));
return articles.map(article -> MapperUtils.getModelMapper().map(article, ArticleResponseForCardBox.class));
}
/*
@@ -98,7 +97,7 @@ public class ArticleQueries implements ArticleQueriesUseCase {
@Override
public ArticleResponseForEdit getArticleForEdit(Long id){
Article article = articleRepositoryPort.findArticleByIdFetchCategoryAndTags(id);
ArticleResponseForEdit articleDto = modelMapper.map(article, ArticleResponseForEdit.class);
ArticleResponseForEdit articleDto = MapperUtils.getModelMapper().map(article, ArticleResponseForEdit.class);
List<String> articleTagStrings = article.getArticleTagLists()
.stream()
.map(articleTag -> articleTag.getTags().getName())
@@ -113,7 +112,7 @@ public class ArticleQueries implements ArticleQueriesUseCase {
public ArticleResponseForDetail getArticleForDetail(Long id){
Article article = articleRepositoryPort.findArticleByIdFetchCategoryAndTags(id);
ArticleResponseForDetail articleResponseForDetail =
modelMapper.map(article, ArticleResponseForDetail.class);
MapperUtils.getModelMapper().map(article, ArticleResponseForDetail.class);
List<String> tags =
article.getArticleTagLists()
@@ -133,7 +132,7 @@ public class ArticleQueries implements ArticleQueriesUseCase {
Category category = categoryUseCase.findCategory(categoryName);
return articleRepositoryPort.findTop6ByCategoryOrderByIdDesc(category)
.stream()
.map(article -> modelMapper.map(article, ArticleResponseByCategory.class))
.map(article -> MapperUtils.getModelMapper().map(article, ArticleResponseByCategory.class))
.collect(Collectors.toList());
}
/*
@@ -144,7 +143,7 @@ public class ArticleQueries implements ArticleQueriesUseCase {
return articleRepositoryPort
.findAllByArticleTagsOrderById(PageRequest.of(pageResolve(page), 5), tag)
.map(article ->
modelMapper.map(article, ArticleResponseForCardBox.class));
MapperUtils.getModelMapper().map(article, ArticleResponseForCardBox.class));
}
/*
- 검색어별 게시물 페이징 처리해서 가져오기
@@ -154,7 +153,7 @@ public class ArticleQueries implements ArticleQueriesUseCase {
return articleRepositoryPort
.findAllByKeywordOrderById(PageRequest.of(pageResolve(page),5), keyword)
.map(article ->
modelMapper.map(article, ArticleResponseForCardBox.class));
MapperUtils.getModelMapper().map(article, ArticleResponseForCardBox.class));
}
/*
- 페이지 시작점 0~1변경 메서드

View File

@@ -5,7 +5,7 @@ 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 org.modelmapper.ModelMapper;
import myblog.blog.shared.utils.MapperUtils;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -19,7 +19,6 @@ import java.util.stream.Collectors;
public class CategoryQueries implements CategoryQueriesUseCase {
private final CategoryRepositoryPort categoryRepositoryPort;
private final ModelMapper modelMapper;
/*
- 카테고리와 카테고리별 아티클 수 찾기
@@ -47,7 +46,7 @@ public class CategoryQueries implements CategoryQueriesUseCase {
public List<CategorySimpleDto> findCategoryByTier(int tier) {
return categoryRepositoryPort.findAllByTierIs(tier)
.stream()
.map(category -> modelMapper.map(category, CategorySimpleDto.class))
.map(category -> MapperUtils.getModelMapper().map(category, CategorySimpleDto.class))
.collect(Collectors.toList());
}
}

View File

@@ -19,18 +19,6 @@ public class AppConfig {
@Value("${cloud.aws.credentials.secretKey}")
private String AWS_SECRET_ACCESS_KEY;
/*
- DTO <-> 엔티티 매퍼 빈등록
*/
@Bean
public ModelMapper modelMapper(){
ModelMapper modelMapper = new ModelMapper();
modelMapper.getConfiguration()
.setFieldAccessLevel(org.modelmapper.config.Configuration.AccessLevel.PRIVATE)
.setFieldMatchingEnabled(true);
return modelMapper;
}
/**
* AWS S3 설정
*/