Skip to content

Commit

Permalink
[Refactor] 회원이 작성한 글 전체 가져오기로 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
hen715 committed Nov 19, 2024
1 parent 1a242ed commit 673141c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,9 @@ public ResponseEntity<ResponseDto<List<MemberResponseDto>>> getAllMember(){
,@ApiResponse(responseCode = "400",description = "정렬의 기준값이 올바르지 않습니다.",content = @Content(schema = @Schema(implementation = ResponseDto.class)))
})
@GetMapping("/posts")
public ResponseEntity<ResponseDto<List<PostListResponseDto>>> getAllPost(@AuthenticationPrincipal Member member, @RequestParam(required = false) String sort
,@RequestParam(required = false,defaultValue = "1") @Min(1) int page){
public ResponseEntity<ResponseDto<List<PostListResponseDto>>> getAllPost(@AuthenticationPrincipal Member member, @RequestParam(required = false) String sort){
log.info("회원이 작성한 모든 글 가져오기 호출 id:{}",member.getId());
return ResponseEntity.ok(ResponseDto.of(postService.getPostByMember(member,sort,page),"회원이 작성한 모든 게시글 가져오기 성공"));
return ResponseEntity.ok(ResponseDto.of(postService.getPostByMember(member,sort),"회원이 작성한 모든 게시글 가져오기 성공"));
}

@Operation(summary = "회원이 스크랩한 모든 글 가져오기",description = "url 헤더에 Auth 토큰을 담아 보내주세요. 정렬기준 sort(date/공백(최신순), like, scrap)를, 페이지(공백일 시 1)를 보내주세요.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ public interface PostRepository extends JpaRepository<Post,Long> {
List<Post> findAllByIdLessThanOrderByIdDesc(Long id, Pageable pageable);
List<Post> findByCategoryAndIdLessThanOrderByIdDesc(String category,Long id,Pageable pageable);
long count();
Page<Post> findAllByMemberOrderByIdDesc(Member member,Pageable pageable);
Page<Post> findAllByMemberOrderByGoodDescIdDesc(Member member,Pageable pageable);
Page<Post> findAllByMemberOrderByScrapDescIdDesc(Member member,Pageable pageable);
List<Post> findAllByMemberOrderByIdDesc(Member member);
List<Post> findAllByMemberOrderByGoodDescIdDesc(Member member);
List<Post> findAllByMemberOrderByScrapDescIdDesc(Member member);
@Query(value = "SELECT * FROM post WHERE MATCH(title, content) AGAINST(?1 IN NATURAL LANGUAGE MODE)", nativeQuery = true)
Page<Post> searchByKeyword(String keyword,Pageable pageable);
@Query(value = "SELECT * FROM post WHERE MATCH(title, content) AGAINST(?1 IN BOOLEAN MODE) ORDER BY good DESC", nativeQuery = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,22 +258,21 @@ public int scrapPost(Member member, Long postId){
}

@Transactional(readOnly = true)
public List<PostListResponseDto> getPostByMember(Member member, String sort, int page){
Pageable pageable = PageRequest.of(page>0?--page:page,8);
public List<PostListResponseDto> getPostByMember(Member member, String sort){
if(sort==null||sort.equals("date")) {
return postRepository.findAllByMemberOrderByIdDesc(member,pageable)
return postRepository.findAllByMemberOrderByIdDesc(member)
.stream()
.map(this::getPostListResponseDto)
.collect(Collectors.toList());
}
else if(sort.equals("like")){
return postRepository.findAllByMemberOrderByGoodDescIdDesc(member,pageable)
return postRepository.findAllByMemberOrderByGoodDescIdDesc(member)
.stream()
.map(this::getPostListResponseDto)
.collect(Collectors.toList());
}
else if(sort.equals("scrap")){
return postRepository.findAllByMemberOrderByScrapDescIdDesc(member,pageable)
return postRepository.findAllByMemberOrderByScrapDescIdDesc(member)
.stream()
.map(this::getPostListResponseDto)
.collect(Collectors.toList());
Expand Down

0 comments on commit 673141c

Please sign in to comment.