Skip to content

Commit

Permalink
Merge pull request #84 from dongkyun0713/dongkyun
Browse files Browse the repository at this point in the history
feat(matchingPost) : ์นดํ…Œ๊ณ ๋ฆฌ ๋ณ„ ๋ถ„๋ฅ˜ ์ถ”๊ฐ€
  • Loading branch information
dongkyun0713 authored Feb 24, 2024
2 parents 8ef63b9 + dba689b commit b14aaef
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 b14aaef

Please sign in to comment.