diff --git a/Titto_Backend/src/main/java/com/example/titto_backend/matchingBoard/controller/MatchingBoardController.java b/Titto_Backend/src/main/java/com/example/titto_backend/matchingBoard/controller/MatchingBoardController.java index 860580f..3748253 100644 --- a/Titto_Backend/src/main/java/com/example/titto_backend/matchingBoard/controller/MatchingBoardController.java +++ b/Titto_Backend/src/main/java/com/example/titto_backend/matchingBoard/controller/MatchingBoardController.java @@ -1,5 +1,6 @@ package com.example.titto_backend.matchingBoard.controller; +import com.example.titto_backend.matchingBoard.domain.matchingBoard.Category; import com.example.titto_backend.matchingBoard.dto.request.MatchingPostRequest.MatchingPostPagingRequestDto; import com.example.titto_backend.matchingBoard.dto.response.matchingPostResponse.MatchingPostPagingResponseDto; import com.example.titto_backend.matchingBoard.service.matchingBoard.MatchingBoardService; @@ -53,4 +54,19 @@ public MatchingPostPagingResponseDto searchByKeyWord(@RequestParam("page") int p return matchingBoardService.searchByKeyWord(requestDto, keyWord); } + @GetMapping("/category") + @Operation( + summary = "매칭 게시판 카테고리 분류", + description = "카테고리 별로 결과를 출력합니다", + responses = { + @ApiResponse(responseCode = "200", description = "요청 성공"), + @ApiResponse(responseCode = "403", description = "인증 문제 발생"), + @ApiResponse(responseCode = "500", description = "관리자 문의") + }) + public MatchingPostPagingResponseDto findByCategory(@RequestParam("page") int page, + @RequestParam Category category) { + MatchingPostPagingRequestDto requestDto = new MatchingPostPagingRequestDto(); + requestDto.setPage(page + 1); + return matchingBoardService.findByCategory(requestDto, category); + } } diff --git a/Titto_Backend/src/main/java/com/example/titto_backend/matchingBoard/repository/matchingBoard/MatchingPostRepository.java b/Titto_Backend/src/main/java/com/example/titto_backend/matchingBoard/repository/matchingBoard/MatchingPostRepository.java index ef6bd71..6c1bad0 100644 --- a/Titto_Backend/src/main/java/com/example/titto_backend/matchingBoard/repository/matchingBoard/MatchingPostRepository.java +++ b/Titto_Backend/src/main/java/com/example/titto_backend/matchingBoard/repository/matchingBoard/MatchingPostRepository.java @@ -1,5 +1,6 @@ package com.example.titto_backend.matchingBoard.repository.matchingBoard; +import com.example.titto_backend.matchingBoard.domain.matchingBoard.Category; import com.example.titto_backend.matchingBoard.domain.matchingBoard.MatchingPost; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; @@ -9,4 +10,6 @@ @Repository public interface MatchingPostRepository extends JpaRepository { Page findByTitleContaining(String keyword, Pageable pageable); + + Page findByCategory(Category category, Pageable pageable); } diff --git a/Titto_Backend/src/main/java/com/example/titto_backend/matchingBoard/service/matchingBoard/MatchingBoardService.java b/Titto_Backend/src/main/java/com/example/titto_backend/matchingBoard/service/matchingBoard/MatchingBoardService.java index 29fc470..4cff7df 100644 --- a/Titto_Backend/src/main/java/com/example/titto_backend/matchingBoard/service/matchingBoard/MatchingBoardService.java +++ b/Titto_Backend/src/main/java/com/example/titto_backend/matchingBoard/service/matchingBoard/MatchingBoardService.java @@ -1,5 +1,6 @@ package com.example.titto_backend.matchingBoard.service.matchingBoard; +import com.example.titto_backend.matchingBoard.domain.matchingBoard.Category; import com.example.titto_backend.matchingBoard.domain.matchingBoard.MatchingPost; import com.example.titto_backend.matchingBoard.dto.request.MatchingPostRequest.MatchingPostPagingRequestDto; import com.example.titto_backend.matchingBoard.dto.response.matchingPostResponse.MatchingPostPagingResponseDto; @@ -37,6 +38,14 @@ public MatchingPostPagingResponseDto searchByKeyWord(MatchingPostPagingRequestDt return MatchingPostPagingResponseDto.from(matchingPosts); } + public MatchingPostPagingResponseDto findByCategory(MatchingPostPagingRequestDto matchingPostPagingRequestDto, Category category) { + int page = matchingPostPagingRequestDto.getPage() - 1; + + Sort sort = Sort.by(Sort.Direction.DESC, "matchingPostId"); + Pageable pageable = PageRequest.of(page, 10, sort); + Page matchingPosts = matchingPostRepository.findByCategory(category, pageable); + return MatchingPostPagingResponseDto.from(matchingPosts); + } }