diff --git a/src/main/java/com/gamegoo/controller/board/BoardController.java b/src/main/java/com/gamegoo/controller/board/BoardController.java index db81a5a8..07c79e84 100644 --- a/src/main/java/com/gamegoo/controller/board/BoardController.java +++ b/src/main/java/com/gamegoo/controller/board/BoardController.java @@ -111,9 +111,20 @@ public ApiResponse delete(@PathVariable Long postId @GetMapping("/list") @Operation(summary = "게시판 글 목록 조회 API", description = "게시판에서 글 목록을 조회하는 API 입니다.") - @Parameter(name = "pageIdx", description = "조회할 페이지 번호를 입력해주세요.") - public ApiResponse> boardList(@RequestParam(defaultValue = "1") int pageIdx){ - List result = boardService.getBoardList(pageIdx); + @Parameter(name = "pageIdx", description = "조회할 페이지 번호를 입력해주세요. 페이지 당 20개의 게시물을 볼 수 있습니다.") + public ApiResponse> boardList(@RequestParam(defaultValue = "1") int pageIdx, + @RequestParam(required = false) Integer mode, + @RequestParam(required = false) String tier, + @RequestParam(required = false) Integer mainPosition, + @RequestParam(required = false) Boolean voice){ + + // <포지션 정보> 전체: 0, 탑: 1, 정글: 2, 미드: 3, 바텀:4, 서포터:5 + if (mainPosition != null && mainPosition == 0) { + // 전체 포지션 선택 시 필터링에서 제외 + mainPosition = null; + } + + List result = boardService.getBoardList(mode,tier,mainPosition,voice,pageIdx); return ApiResponse.onSuccess(result); } diff --git a/src/main/java/com/gamegoo/dto/board/BoardResponse.java b/src/main/java/com/gamegoo/dto/board/BoardResponse.java index 36fd6915..b4888884 100644 --- a/src/main/java/com/gamegoo/dto/board/BoardResponse.java +++ b/src/main/java/com/gamegoo/dto/board/BoardResponse.java @@ -68,6 +68,7 @@ public static class boardListResponseDTO{ List championList; Double winRate; LocalDateTime createdAt; + Boolean voice; } @Getter diff --git a/src/main/java/com/gamegoo/repository/board/BoardRepository.java b/src/main/java/com/gamegoo/repository/board/BoardRepository.java index e3ed64e6..e9abb774 100644 --- a/src/main/java/com/gamegoo/repository/board/BoardRepository.java +++ b/src/main/java/com/gamegoo/repository/board/BoardRepository.java @@ -4,9 +4,23 @@ import org.springframework.data.domain.Page; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.domain.Pageable; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; import java.util.List; public interface BoardRepository extends JpaRepository{ Page findByMemberId(Long memberId, Pageable pageable); + + @Query("SELECT b From Board b JOIN b.member m WHERE" + + "(:mode IS NULL OR b.mode = :mode) AND " + + "(:tier IS NULL OR m.tier = :tier) AND " + + "(:mainPosition IS NULL OR b.mainPosition = :mainPosition OR b.subPosition = :mainPosition) AND " + + "(:voice IS NULL OR b.voice = :voice)") + + Page findByFilters(@Param("mode") Integer mode, + @Param("tier") String tier, + @Param("mainPosition") Integer mainPosition, + @Param("voice") Boolean voice, + Pageable pageable); } diff --git a/src/main/java/com/gamegoo/service/board/BoardService.java b/src/main/java/com/gamegoo/service/board/BoardService.java index 4c5f1542..ccf157fd 100644 --- a/src/main/java/com/gamegoo/service/board/BoardService.java +++ b/src/main/java/com/gamegoo/service/board/BoardService.java @@ -238,7 +238,7 @@ public void delete(Long boardId, Long memberId){ // 게시판 글 목록 조회 @Transactional(readOnly = true) - public List getBoardList(int pageIdx){ + public List getBoardList(Integer mode, String tier, Integer mainPosition, Boolean voice, int pageIdx){ // pageIdx 값 검증. if (pageIdx <= 0){ @@ -248,7 +248,7 @@ public List getBoardList(int pageIdx){ // 사용자로부터 받은 pageIdx를 1 감소 -> pageIdx=1 일 때, 1 페이지. Pageable pageable = PageRequest.of(pageIdx-1, PAGE_SIZE, Sort.by(Sort.Direction.DESC, "createdAt")); - List boards = boardRepository.findAll(pageable).getContent(); + List boards = boardRepository.findByFilters(mode, tier, mainPosition, voice, pageable).getContent(); return boards.stream().map(board -> { @@ -268,6 +268,7 @@ public List getBoardList(int pageIdx){ .championList(member.getMemberChampionList().stream().map(MemberChampion::getId).collect(Collectors.toList())) .winRate(member.getWinRate()) .createdAt(board.getCreatedAt()) + .voice(board.getVoice()) .build(); }).collect(Collectors.toList());