모델 매퍼 맵 스트럭쳐로 스택 마이그레이션
This commit is contained in:
@@ -46,7 +46,6 @@ dependencies {
|
|||||||
implementation 'io.sentry:sentry-spring-boot-starter:5.6.1'
|
implementation 'io.sentry:sentry-spring-boot-starter:5.6.1'
|
||||||
implementation 'com.querydsl:querydsl-jpa'
|
implementation 'com.querydsl:querydsl-jpa'
|
||||||
implementation 'com.github.node-gradle:gradle-node-plugin:3.1.0'
|
implementation 'com.github.node-gradle:gradle-node-plugin:3.1.0'
|
||||||
implementation group: 'org.modelmapper', name: 'modelmapper', version: '2.4.4'
|
|
||||||
implementation group: 'org.kohsuke', name: 'github-api', version: '1.133'
|
implementation group: 'org.kohsuke', name: 'github-api', version: '1.133'
|
||||||
implementation group: 'org.apache.commons', name: 'commons-text', version: '1.9'
|
implementation group: 'org.apache.commons', name: 'commons-text', version: '1.9'
|
||||||
implementation group: 'com.atlassian.commonmark', name: 'commonmark', version: '0.17.0'
|
implementation group: 'com.atlassian.commonmark', name: 'commonmark', version: '0.17.0'
|
||||||
@@ -56,6 +55,10 @@ dependencies {
|
|||||||
implementation group: 'net.sf.ehcache', name: 'ehcache', version: '2.10.9.2'
|
implementation group: 'net.sf.ehcache', name: 'ehcache', version: '2.10.9.2'
|
||||||
implementation group: 'com.amazonaws', name: 'aws-java-sdk-s3', version: '1.12.152'
|
implementation group: 'com.amazonaws', name: 'aws-java-sdk-s3', version: '1.12.152'
|
||||||
|
|
||||||
|
implementation 'org.mapstruct:mapstruct:1.4.2.Final'
|
||||||
|
annotationProcessor "org.mapstruct:mapstruct-processor:1.4.2.Final"
|
||||||
|
annotationProcessor'org.projectlombok:lombok-mapstruct-binding:0.2.0'
|
||||||
|
|
||||||
|
|
||||||
compileOnly 'org.projectlombok:lombok'
|
compileOnly 'org.projectlombok:lombok'
|
||||||
developmentOnly 'org.springframework.boot:spring-boot-devtools'
|
developmentOnly 'org.springframework.boot:spring-boot-devtools'
|
||||||
|
|||||||
@@ -0,0 +1,35 @@
|
|||||||
|
package myblog.blog.article.application;
|
||||||
|
|
||||||
|
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 ArticleDtoMapper {
|
||||||
|
ArticleResponseForCardBox cardBox(Article article);
|
||||||
|
@Mappings({
|
||||||
|
@Mapping(target = "articleTagList",ignore = true)
|
||||||
|
})
|
||||||
|
ArticleResponseForEdit edit(Article article);
|
||||||
|
@Mappings({
|
||||||
|
@Mapping(target = "tags",ignore = true),
|
||||||
|
@Mapping(source = "article.category.title", target = "category"),
|
||||||
|
@Mapping(source = "article.member.id", target = "memberId"),
|
||||||
|
})
|
||||||
|
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);
|
||||||
|
}
|
||||||
@@ -32,6 +32,7 @@ public class ArticleQueries implements ArticleQueriesUseCase {
|
|||||||
|
|
||||||
private final ArticleRepositoryPort articleRepositoryPort;
|
private final ArticleRepositoryPort articleRepositoryPort;
|
||||||
private final CategoryUseCase categoryUseCase;
|
private final CategoryUseCase categoryUseCase;
|
||||||
|
private final ArticleDtoMapper articleDtoMapper;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
- 메인화면 위한 인기 아티클 6개 목록 가져오기
|
- 메인화면 위한 인기 아티클 6개 목록 가져오기
|
||||||
@@ -44,7 +45,7 @@ public class ArticleQueries implements ArticleQueriesUseCase {
|
|||||||
public List<ArticleResponseForCardBox> getPopularArticles() {
|
public List<ArticleResponseForCardBox> getPopularArticles() {
|
||||||
return articleRepositoryPort.findTop6ByOrderByHitDesc()
|
return articleRepositoryPort.findTop6ByOrderByHitDesc()
|
||||||
.stream()
|
.stream()
|
||||||
.map(article -> MapperUtils.getModelMapper().map(article, ArticleResponseForCardBox.class))
|
.map(articleDtoMapper::cardBox)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
@@ -59,7 +60,7 @@ public class ArticleQueries implements ArticleQueriesUseCase {
|
|||||||
.findByOrderByIdDesc(lastArticleId, 5);
|
.findByOrderByIdDesc(lastArticleId, 5);
|
||||||
return articles
|
return articles
|
||||||
.stream()
|
.stream()
|
||||||
.map(article -> MapperUtils.getModelMapper().map(article, ArticleResponseForCardBox.class))
|
.map(articleDtoMapper::cardBox)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
@@ -85,7 +86,7 @@ public class ArticleQueries implements ArticleQueriesUseCase {
|
|||||||
}
|
}
|
||||||
if(articles == null) throw new ArticleNotFoundException();
|
if(articles == null) throw new ArticleNotFoundException();
|
||||||
|
|
||||||
return articles.stream().map(article -> MapperUtils.getModelMapper().map(article, ArticleResponseForCardBox.class)).collect(Collectors.toList());
|
return articles.stream().map(articleDtoMapper::cardBox).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -94,7 +95,7 @@ public class ArticleQueries implements ArticleQueriesUseCase {
|
|||||||
@Override
|
@Override
|
||||||
public ArticleResponseForEdit getArticleForEdit(Long id){
|
public ArticleResponseForEdit getArticleForEdit(Long id){
|
||||||
Article article = articleRepositoryPort.findArticleByIdFetchCategoryAndTags(id);
|
Article article = articleRepositoryPort.findArticleByIdFetchCategoryAndTags(id);
|
||||||
ArticleResponseForEdit articleDto = MapperUtils.getModelMapper().map(article, ArticleResponseForEdit.class);
|
ArticleResponseForEdit articleDto = articleDtoMapper.edit(article);
|
||||||
List<String> articleTagStrings = article.getArticleTagLists()
|
List<String> articleTagStrings = article.getArticleTagLists()
|
||||||
.stream()
|
.stream()
|
||||||
.map(articleTag -> articleTag.getTags().getName())
|
.map(articleTag -> articleTag.getTags().getName())
|
||||||
@@ -108,8 +109,7 @@ public class ArticleQueries implements ArticleQueriesUseCase {
|
|||||||
@Override
|
@Override
|
||||||
public ArticleResponseForDetail getArticleForDetail(Long id){
|
public ArticleResponseForDetail getArticleForDetail(Long id){
|
||||||
Article article = articleRepositoryPort.findArticleByIdFetchCategoryAndTags(id);
|
Article article = articleRepositoryPort.findArticleByIdFetchCategoryAndTags(id);
|
||||||
ArticleResponseForDetail articleResponseForDetail =
|
ArticleResponseForDetail articleResponseForDetail = articleDtoMapper.detail(article);
|
||||||
MapperUtils.getModelMapper().map(article, ArticleResponseForDetail.class);
|
|
||||||
|
|
||||||
List<String> tags =
|
List<String> tags =
|
||||||
article.getArticleTagLists()
|
article.getArticleTagLists()
|
||||||
@@ -129,7 +129,7 @@ public class ArticleQueries implements ArticleQueriesUseCase {
|
|||||||
Category category = categoryUseCase.findCategory(categoryName);
|
Category category = categoryUseCase.findCategory(categoryName);
|
||||||
return articleRepositoryPort.findTop6ByCategoryOrderByIdDesc(category)
|
return articleRepositoryPort.findTop6ByCategoryOrderByIdDesc(category)
|
||||||
.stream()
|
.stream()
|
||||||
.map(article -> MapperUtils.getModelMapper().map(article, ArticleResponseByCategory.class))
|
.map(articleDtoMapper::category)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
@@ -139,8 +139,7 @@ public class ArticleQueries implements ArticleQueriesUseCase {
|
|||||||
public Page<ArticleResponseForCardBox> getArticlesByTag(String tag, Integer page) {
|
public Page<ArticleResponseForCardBox> getArticlesByTag(String tag, Integer page) {
|
||||||
return articleRepositoryPort
|
return articleRepositoryPort
|
||||||
.findAllByArticleTagsOrderById(PageRequest.of(pageResolve(page), 5), tag)
|
.findAllByArticleTagsOrderById(PageRequest.of(pageResolve(page), 5), tag)
|
||||||
.map(article ->
|
.map(articleDtoMapper::cardBox);
|
||||||
MapperUtils.getModelMapper().map(article, ArticleResponseForCardBox.class));
|
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
- 검색어별 게시물 페이징 처리해서 가져오기
|
- 검색어별 게시물 페이징 처리해서 가져오기
|
||||||
@@ -149,8 +148,7 @@ public class ArticleQueries implements ArticleQueriesUseCase {
|
|||||||
public Page<ArticleResponseForCardBox> getArticlesByKeyword(String keyword, Integer page) {
|
public Page<ArticleResponseForCardBox> getArticlesByKeyword(String keyword, Integer page) {
|
||||||
return articleRepositoryPort
|
return articleRepositoryPort
|
||||||
.findAllByKeywordOrderById(PageRequest.of(pageResolve(page),5), keyword)
|
.findAllByKeywordOrderById(PageRequest.of(pageResolve(page),5), keyword)
|
||||||
.map(article ->
|
.map(articleDtoMapper::cardBox);
|
||||||
MapperUtils.getModelMapper().map(article, ArticleResponseForCardBox.class));
|
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
- 페이지 시작점 0~1변경 메서드
|
- 페이지 시작점 0~1변경 메서드
|
||||||
|
|||||||
@@ -17,11 +17,12 @@ import java.util.stream.Collectors;
|
|||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class TagsQueries implements TagsQueriesUseCase {
|
public class TagsQueries implements TagsQueriesUseCase {
|
||||||
private final TagRepositoryPort tagRepositoryPort;
|
private final TagRepositoryPort tagRepositoryPort;
|
||||||
|
private final ArticleDtoMapper articleDtoMapper;
|
||||||
|
|
||||||
public List<TagsResponse> findAllTagDtos(){
|
public List<TagsResponse> findAllTagDtos(){
|
||||||
var tags = tagRepositoryPort.findAll();
|
var tags = tagRepositoryPort.findAll();
|
||||||
return tags.stream()
|
return tags.stream()
|
||||||
.map(tag -> MapperUtils.getModelMapper().map(tag, TagsResponse.class))
|
.map(articleDtoMapper::of)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ public class ArticleResponseForEdit {
|
|||||||
private String content;
|
private String content;
|
||||||
private String toc;
|
private String toc;
|
||||||
private String thumbnailUrl;
|
private String thumbnailUrl;
|
||||||
|
private List<String> articleTagList;
|
||||||
private List<String> articleTagList = new ArrayList<>();
|
|
||||||
private Category category;
|
private Category category;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package myblog.blog.category.appliacation;
|
package myblog.blog.category.appliacation;
|
||||||
|
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import myblog.blog.article.application.ArticleDtoMapper;
|
||||||
import myblog.blog.category.appliacation.port.incomming.CategoryQueriesUseCase;
|
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.CategorySimpleDto;
|
||||||
import myblog.blog.category.appliacation.port.incomming.response.CategoryViewForLayout;
|
import myblog.blog.category.appliacation.port.incomming.response.CategoryViewForLayout;
|
||||||
@@ -19,6 +20,7 @@ import java.util.stream.Collectors;
|
|||||||
public class CategoryQueries implements CategoryQueriesUseCase {
|
public class CategoryQueries implements CategoryQueriesUseCase {
|
||||||
|
|
||||||
private final CategoryRepositoryPort categoryRepositoryPort;
|
private final CategoryRepositoryPort categoryRepositoryPort;
|
||||||
|
private final ArticleDtoMapper articleDtoMapper;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
- 카테고리와 카테고리별 아티클 수 찾기
|
- 카테고리와 카테고리별 아티클 수 찾기
|
||||||
@@ -46,7 +48,7 @@ public class CategoryQueries implements CategoryQueriesUseCase {
|
|||||||
public List<CategorySimpleDto> findCategoryByTier(int tier) {
|
public List<CategorySimpleDto> findCategoryByTier(int tier) {
|
||||||
return categoryRepositoryPort.findAllByTierIs(tier)
|
return categoryRepositoryPort.findAllByTierIs(tier)
|
||||||
.stream()
|
.stream()
|
||||||
.map(category -> MapperUtils.getModelMapper().map(category, CategorySimpleDto.class))
|
.map(articleDtoMapper::categorySimpleDto)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import com.amazonaws.auth.BasicAWSCredentials;
|
|||||||
import com.amazonaws.regions.Regions;
|
import com.amazonaws.regions.Regions;
|
||||||
import com.amazonaws.services.s3.AmazonS3;
|
import com.amazonaws.services.s3.AmazonS3;
|
||||||
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
|
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
|
||||||
import org.modelmapper.ModelMapper;
|
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|||||||
@@ -1,24 +1,13 @@
|
|||||||
package myblog.blog.shared.utils;
|
package myblog.blog.shared.utils;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import org.modelmapper.ModelMapper;
|
|
||||||
|
|
||||||
public class MapperUtils {
|
public class MapperUtils {
|
||||||
private static final ModelMapper modelMapper;
|
|
||||||
private static final Gson gson;
|
private static final Gson gson;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
modelMapper = new ModelMapper();
|
|
||||||
modelMapper.getConfiguration()
|
|
||||||
.setFieldAccessLevel(org.modelmapper.config.Configuration.AccessLevel.PRIVATE)
|
|
||||||
.setFieldMatchingEnabled(true);
|
|
||||||
gson = new Gson();
|
gson = new Gson();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ModelMapper getModelMapper(){
|
|
||||||
return modelMapper;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Gson getGson(){
|
public static Gson getGson(){
|
||||||
return gson;
|
return gson;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user