211110 메인화면 개발중

1. 메인화면에 필요한 게시물 리스트 조회 로직과 화면 렌더링 구현
2. 조회수순으로 메인화면 노출과 최신 업로드 순 게시물 노출 로직 구분
3. 무한스크롤 구현
4. 스크롤 화살표 구현
5. 계층형 카테고리 개발과 화면 렌더링 완료
   - 롤업함수와 백트래킹으로 구현
This commit is contained in:
jinia91
2021-11-10 19:09:14 +09:00
parent f35a9dab0d
commit 8e0dc43370
58 changed files with 3443 additions and 490 deletions

View File

@@ -1,40 +1,62 @@
package myblog.blog.article.controller;
import lombok.RequiredArgsConstructor;
import myblog.blog.article.dto.ArticleForMainView;
import myblog.blog.article.dto.NewArticleDto;
import myblog.blog.article.service.ArticleService;
import myblog.blog.category.dto.CategoryForMainView;
import myblog.blog.category.service.CategoryService;
import myblog.blog.member.auth.PrincipalDetails;
import myblog.blog.tags.service.TagsService;
import org.springframework.data.domain.Slice;
import org.springframework.security.core.Authentication;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@Controller
@RequiredArgsConstructor
public class ArticleController {
private final ArticleService articleService;
private final TagsService tagsService;
private final CategoryService categoryService;
@GetMapping("article/write")
public String writeArticleForm(NewArticleDto newArticleDto, Model model){
CategoryForMainView categoryForView = categoryService.getCategoryForView();
model.addAttribute("category",categoryForView);
model.addAttribute(newArticleDto);
return "articleWriteForm";
return "article/articleWriteForm";
}
@PostMapping("article/write")
@Transactional
public String WriteArticle(@ModelAttribute NewArticleDto newArticleDto, Authentication authentication){
PrincipalDetails principal = (PrincipalDetails) authentication.getPrincipal();
newArticleDto.setMemberId(principal.getMemberId());
Long articleId = articleService.writeArticle(newArticleDto);
articleService.writeArticle(newArticleDto);
return "redirect:/";
}
@GetMapping("/main/article/{pageNum}")
public @ResponseBody
List<ArticleForMainView> nextPage(@PathVariable int pageNum){
return articleService.getRecentArticles(pageNum).getContent();
}
}