Skip to content

Commit

Permalink
Merge pull request #44 from goormthon-Univ/feature/43
Browse files Browse the repository at this point in the history
[Feat] Add `GetPostsScrap`
  • Loading branch information
chaeeun-Han committed Mar 22, 2024
2 parents 5f1c1ae + 3bb77fd commit 9b5018a
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,19 @@ public ResponseEntity<? super GetPostsAllResponseDto> getAllScrapPost(@RequestHe
ResponseEntity<? super GetPostsAllResponseDto> response = postsService.getAllScrapPost(kakao_uid, page);
return response;
}

@GetMapping("/posts/all-scrap-list")
public ResponseEntity<? super GetPostsAllResponseDto> getAllScrapPostNoPage(@RequestHeader(value="Authorization") String token) {
Long kakao_uid;
try {
kakao_uid = authService.getKakaoUserInfo(token).getId();
if (kakao_uid == null)
return PostsResponseDto.noAuthentication();
} catch (Exception exception) {
log.info(exception.getMessage());
return PostsResponseDto.databaseError();
}
ResponseEntity<? super GetPostsAllResponseDto> response = postsService.getAllScrapPostNoPage(kakao_uid);
return response;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ public interface PostsRepository extends JpaRepository<Posts, Long> {

Posts findByPostId(Long postId);

List<Posts> findAllByPostId(Long postId);
@Query("SELECT p FROM Posts p WHERE p.postId IN :postIds")
List<Posts> findAllByPostId(List<Long> postIds);

@Query("SELECT p FROM Posts p WHERE p.postId IN :postIds")
Page<Posts> findByPostIds(@Param("postIds") List<Long> postIds, PageRequest pageRequest);
Expand Down
23 changes: 23 additions & 0 deletions src/main/java/com/beotkkot/qtudy/service/posts/PostsService.java
Original file line number Diff line number Diff line change
Expand Up @@ -358,4 +358,27 @@ public ResponseEntity<? super GetPostsAllResponseDto> getAllScrapPost(Long kakao
GetPostsAllResponseDto responseDto = new GetPostsAllResponseDto(postListItems, page, totalPages);
return responseDto.success(postListItems, page,totalPages);
}

@Transactional
public ResponseEntity<? super GetPostsAllResponseDto> getAllScrapPostNoPage(Long kakao_uid) {
List<PostListItem> postListItems = new ArrayList<>();
int totalPages;
try {
if (userRepo.findByKakaoId(kakao_uid) == null) return PutScrapResponseDto.notExistUser();

List<Long> postIdList = scrapRepo.findPostIdsByUserId(kakao_uid);
List<Posts> posts = postsRepo.findAllByPostId(postIdList);

if (posts == null) return PutScrapResponseDto.notExistedPost();

for (Posts post : posts)
postListItems.add(PostListItem.of(post));
} catch (Exception exception) {
exception.printStackTrace();
return ResponseDto.databaseError();
}

GetPostsAllResponseDto responseDto = new GetPostsAllResponseDto(postListItems, 0, 0);
return responseDto.success(postListItems, 0, 0);
}
}

0 comments on commit 9b5018a

Please sign in to comment.