infrastructure layer domain인 slice가 뷰단까지 침투하는 부분을 리팩토링, page에 대한 고민중
This commit is contained in:
@@ -104,13 +104,13 @@ public class ArticleController {
|
||||
@Transactional
|
||||
@GetMapping("article/list")
|
||||
String getArticlesListByCategory(@RequestParam String category,
|
||||
@RequestParam Integer tier,
|
||||
@RequestParam Integer page,
|
||||
@RequestParam int tier,
|
||||
@RequestParam int page,
|
||||
Model model) {
|
||||
PagingBoxHandler pagingBoxHandler =
|
||||
PagingBoxHandler.createOf(page, getTotalArticleCntByCategory(category, categoryQueriesUseCase.getCategoryViewForLayout()));
|
||||
|
||||
Slice<ArticleResponseForCardBox> articleDtoList =
|
||||
List<ArticleResponseForCardBox> articleDtoList =
|
||||
articleQueriesUseCase.getArticlesByCategory(category, tier, pagingBoxHandler.getCurPageNum());
|
||||
|
||||
for(ArticleResponseForCardBox articleDto : articleDtoList){
|
||||
|
||||
@@ -5,6 +5,7 @@ import myblog.blog.article.application.port.outgoing.ArticleRepositoryPort;
|
||||
import myblog.blog.article.domain.Article;
|
||||
import myblog.blog.category.domain.Category;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Slice;
|
||||
import org.springframework.stereotype.Component;
|
||||
@@ -31,8 +32,8 @@ public class ArticleRepositoryAdapter implements ArticleRepositoryPort {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Slice<Article> findByOrderByIdDesc(Pageable pageable) {
|
||||
return jpaArticleRepository.findByOrderByIdDesc(pageable);
|
||||
public List<Article> findByOrderByIdDesc(int page, int size) {
|
||||
return jpaArticleRepository.findByOrderByIdDesc(PageRequest.of(page,size)).getContent();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -41,13 +42,13 @@ public class ArticleRepositoryAdapter implements ArticleRepositoryPort {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Slice<Article> findBySubCategoryOrderByIdDesc(Pageable pageable, String category) {
|
||||
return jpaArticleRepository.findBySubCategoryOrderByIdDesc(pageable,category);
|
||||
public List<Article> findBySubCategoryOrderByIdDesc(int page,int size, String category) {
|
||||
return jpaArticleRepository.findBySubCategoryOrderByIdDesc(PageRequest.of(page, size),category).getContent();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Slice<Article> findBySuperCategoryOrderByIdDesc(Pageable pageable, String category) {
|
||||
return jpaArticleRepository.findBySupCategoryOrderByIdDesc(pageable,category);
|
||||
public List<Article> findBySuperCategoryOrderByIdDesc(int page,int size, String category) {
|
||||
return jpaArticleRepository.findBySupCategoryOrderByIdDesc(PageRequest.of(page, size),category).getContent();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -2,22 +2,22 @@ package myblog.blog.article.application;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import myblog.blog.article.domain.Article;
|
||||
import myblog.blog.category.domain.Category;
|
||||
|
||||
import myblog.blog.article.application.port.incomming.response.ArticleResponseForCardBox;
|
||||
import myblog.blog.article.application.port.incomming.ArticleQueriesUseCase;
|
||||
import myblog.blog.article.application.port.outgoing.ArticleRepositoryPort;
|
||||
|
||||
import myblog.blog.article.domain.Article;
|
||||
import myblog.blog.category.appliacation.port.incomming.CategoryUseCase;
|
||||
import myblog.blog.category.domain.Category;
|
||||
import myblog.blog.article.application.port.incomming.response.ArticleResponseByCategory;
|
||||
import myblog.blog.article.application.port.incomming.response.ArticleResponseForDetail;
|
||||
import myblog.blog.article.application.port.incomming.response.ArticleResponseForEdit;
|
||||
import myblog.blog.category.appliacation.port.incomming.CategoryUseCase;
|
||||
|
||||
import myblog.blog.article.application.port.outgoing.ArticleRepositoryPort;
|
||||
|
||||
import myblog.blog.shared.utils.MapperUtils;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Slice;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@@ -66,28 +66,25 @@ public class ArticleQueries implements ArticleQueriesUseCase {
|
||||
- tier 1은 super / tier 2는 sub
|
||||
*/
|
||||
@Override
|
||||
public Slice<ArticleResponseForCardBox> getArticlesByCategory(String category, Integer tier, Integer page) {
|
||||
Slice<Article> articles = null;
|
||||
public List<ArticleResponseForCardBox> getArticlesByCategory(String category, int tier, int page) {
|
||||
List<Article> articles = null;
|
||||
page = pageResolve(page);
|
||||
|
||||
if (tier.equals(0)) {
|
||||
if (tier == 0) {
|
||||
articles = articleRepositoryPort
|
||||
.findByOrderByIdDesc(
|
||||
PageRequest.of(pageResolve(page), 5));
|
||||
.findByOrderByIdDesc(page, 5);
|
||||
}
|
||||
if (tier.equals(1)) {
|
||||
if (tier == 1) {
|
||||
articles = articleRepositoryPort
|
||||
.findBySuperCategoryOrderByIdDesc(
|
||||
PageRequest.of(pageResolve(page), 5), category);
|
||||
.findBySuperCategoryOrderByIdDesc(page, 5, category);
|
||||
}
|
||||
if (tier.equals(2)) {
|
||||
if (tier == 2) {
|
||||
articles = articleRepositoryPort
|
||||
.findBySubCategoryOrderByIdDesc(
|
||||
PageRequest.of(pageResolve(page), 5), category);
|
||||
.findBySubCategoryOrderByIdDesc(page, 5, category);
|
||||
}
|
||||
|
||||
if(articles == null) throw new IllegalArgumentException("NotFoundArticleException");
|
||||
|
||||
return articles.map(article -> MapperUtils.getModelMapper().map(article, ArticleResponseForCardBox.class));
|
||||
return articles.stream().map(article -> MapperUtils.getModelMapper().map(article, ArticleResponseForCardBox.class)).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -12,7 +12,7 @@ import java.util.List;
|
||||
public interface ArticleQueriesUseCase {
|
||||
List<ArticleResponseForCardBox> getPopularArticles();
|
||||
List<ArticleResponseForCardBox> getRecentArticles(Long lastArticleId);
|
||||
Slice<ArticleResponseForCardBox> getArticlesByCategory(String category, Integer tier, Integer page);
|
||||
List<ArticleResponseForCardBox> getArticlesByCategory(String category, int tier, int page);
|
||||
ArticleResponseForEdit getArticleForEdit(Long id);
|
||||
ArticleResponseForDetail getArticleForDetail(Long id);
|
||||
List<ArticleResponseByCategory> getArticlesByCategoryForDetailView(String category);
|
||||
|
||||
@@ -12,10 +12,10 @@ import java.util.Optional;
|
||||
public interface ArticleRepositoryPort {
|
||||
List<Article> findTop6ByOrderByHitDesc();
|
||||
List<Article> findTop6ByCategoryOrderByIdDesc(Category category);
|
||||
Slice<Article> findByOrderByIdDesc(Pageable pageable);
|
||||
List<Article> findByOrderByIdDesc(int page, int size);
|
||||
List<Article> findByOrderByIdDesc(Long articleId, int size);
|
||||
Slice<Article> findBySubCategoryOrderByIdDesc(Pageable pageable, String category);
|
||||
Slice<Article> findBySuperCategoryOrderByIdDesc(Pageable pageable, String category);
|
||||
List<Article> findBySubCategoryOrderByIdDesc(int page, int size, String category);
|
||||
List<Article> findBySuperCategoryOrderByIdDesc(int page, int size, String category);
|
||||
Article findArticleByIdFetchCategoryAndTags(Long articleId);
|
||||
Page<Article> findAllByArticleTagsOrderById(Pageable pageable, String tag);
|
||||
Page<Article> findAllByKeywordOrderById(Pageable pageable, String keyword);
|
||||
|
||||
@@ -63,7 +63,7 @@
|
||||
<h1 class="text-center" th:text="${param.category}">카테고리 명</h1>
|
||||
<hr>
|
||||
<div id="articlePage-0">
|
||||
<div class="card mb-3 recent-card wow fadeInUp" th:each="article :${articleList.getContent()}">
|
||||
<div class="card mb-3 recent-card wow fadeInUp" th:each="article :${articleList}">
|
||||
<a th:href="@{/article/view(articleId=${article.getId()})}">
|
||||
<div class="row g-0">
|
||||
<div class="col-3">
|
||||
|
||||
Reference in New Issue
Block a user