Skip to content

Commit

Permalink
[FIX] ArticleController list, search 통합
Browse files Browse the repository at this point in the history
  • Loading branch information
ChoiJHyuk committed Jun 18, 2024
1 parent 344c4fb commit efd0157
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ public void createArticle(@RequestParam String title, @RequestParam String conte
articleService.saveArticle(title, content, images, principal.getName());
}
@GetMapping("/list")
public List<ArticleResponseDto> getArticleList(@RequestParam(defaultValue = "0") int page) throws IOException {
return articleService.getArticles(page);
public List<ArticleResponseDto> getArticleList(@RequestParam(defaultValue = "") String keyword, @RequestParam(defaultValue = "0") int page) throws IOException {
return articleService.getArticles(keyword, page);
}

@GetMapping("/mylist")
Expand All @@ -36,11 +36,6 @@ public List<ArticleResponseDto> getMyArticleList(@RequestParam(defaultValue = "0
return articleService.getMyArticles(seniorUser.getUserId(), page);
}

@GetMapping("/search")
public List<ArticleResponseDto> searchArticleList(@RequestParam String keyword, @RequestParam(defaultValue = "0") int page) throws IOException {
return articleService.searchArticles(keyword,page);
}

@DeleteMapping("/delete/{id}")
public void deleteArticle(@PathVariable Long id, Principal principal) throws IOException {
articleService.deleteArticleById(id, principal.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,7 @@ public void saveArticle(String title, String content, List<MultipartFile> images
}
}

public List<ArticleResponseDto> getArticles(int page) throws IOException {
Pageable pageable = PageRequest.of(page, 10, Sort.by("createdAt").descending());
List<Article> articles = articleRepository.findAll(pageable).getContent();
return getArticleResponseDtos(articles);
}

public List<ArticleResponseDto> searchArticles(String keyword, int page) throws IOException {
public List<ArticleResponseDto> getArticles(String keyword, int page) throws IOException {
Pageable pageable = PageRequest.of(page, 10, Sort.by("createdAt").descending());
List<Article> articles = articleRepository.findAllByTitleOrContent(keyword, pageable).getContent();
return getArticleResponseDtos(articles);
Expand Down

0 comments on commit efd0157

Please sign in to comment.