Skip to content

Commit

Permalink
Merge pull request #99 from UMC-ON/feat/boardnpost
Browse files Browse the repository at this point in the history
Feature: 정보/자유게시물의 국가 필터링 기능에 paging 추가
  • Loading branch information
sanggae4133 authored Nov 4, 2024
2 parents c3135a1 + 0112876 commit 5666ed2
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,11 @@ public Page<PostResponseDTO> searchPosts(String keyword, Pageable pageable) {
}

// 국가 필터링 메서드
public List<PostResponseDTO> getPostsByCountryAndBoardType(BoardType boardType, String country) {
public Page<PostResponseDTO> getPostsByCountryAndBoardType(BoardType boardType, String country, Pageable pageable) {
Board board = boardRepository.findByType(boardType)
.orElseThrow(() -> new BadRequestException(ResponseCode.ROW_DOES_NOT_EXIST, "게시판을 찾을 수 없습니다."));
Page<Post> posts = postRepository.findByBoardAndUserCountry(board, country, pageable);

List<Post> posts = postRepository.findByBoardAndUserCountry(board, country);

return posts.stream()
.map(post -> PostResponseDTO.from(post, true))
.collect(Collectors.toList());
return posts.map(post -> PostResponseDTO.from(post, true));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public interface PostRepository extends JpaRepository<Post, Long> {

// 작성자의 국가를 기준으로 게시글 필터링
@Query("SELECT p FROM Post p WHERE p.board = :board AND p.user.country = :country ORDER BY p.createdAt DESC")
List<Post> findByBoardAndUserCountry(@Param("board") Board board, @Param("country") String country);
Page<Post> findByBoardAndUserCountry(@Param("board") Board board, @Param("country") String country, Pageable pageable);


// 특정 게시판에서 최신 게시글 4개 조회
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,12 @@ public ResponseEntity<Void> deletePost(
@Operation(summary = "국가 필터링된 게시글 조회")
@PreAuthorize("@securityService.isNotTemporaryUser()")
@GetMapping("/filter/{boardType}")
public ResponseEntity<List<PostResponseDTO>> searchPostsByCountry(
public ResponseEntity<Page<PostResponseDTO>> searchPostsByCountry(
@PathVariable("boardType") BoardType boardType,
@RequestParam(name = "country") String country
@RequestParam(name = "country") String country,
@ParameterObject Pageable pageable
) {
List<PostResponseDTO> filteredPosts = postService.getPostsByCountryAndBoardType(boardType, country);
Page<PostResponseDTO> filteredPosts = postService.getPostsByCountryAndBoardType(boardType, country, pageable);
return ResponseEntity.ok(filteredPosts);
}

Expand Down

0 comments on commit 5666ed2

Please sign in to comment.