Skip to content

Commit

Permalink
feat(matchingPost) : 카테고리 별 분류 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
dongkyun0713 committed Feb 24, 2024
1 parent 9e3daa6 commit dba689b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -9,4 +10,6 @@
@Repository
public interface MatchingPostRepository extends JpaRepository<MatchingPost, Long> {
Page<MatchingPost> findByTitleContaining(String keyword, Pageable pageable);

Page<MatchingPost> findByCategory(Category category, Pageable pageable);
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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<MatchingPost> matchingPosts = matchingPostRepository.findByCategory(category, pageable);
return MatchingPostPagingResponseDto.from(matchingPosts);
}
}


0 comments on commit dba689b

Please sign in to comment.