From 3a3fcafa1a08766828b427c6a871185abd0bdbe0 Mon Sep 17 00:00:00 2001 From: CokeLee777 Date: Thu, 18 Jan 2024 22:29:34 +0900 Subject: [PATCH] [FIX] fix post sorting --- .../java/com/dailyon/snsservice/entity/Post.java | 8 ++++++++ .../dailyon/snsservice/service/post/PostService.java | 12 +++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/dailyon/snsservice/entity/Post.java b/src/main/java/com/dailyon/snsservice/entity/Post.java index 1f7dbdd..234645f 100644 --- a/src/main/java/com/dailyon/snsservice/entity/Post.java +++ b/src/main/java/com/dailyon/snsservice/entity/Post.java @@ -146,4 +146,12 @@ public void addCommentCount(Integer count) { public void setDeleted(Boolean deleted) { this.isDeleted = deleted; } + + public void setViewCount(Integer viewCount) { + this.viewCount = viewCount; + } + + public void setLikeCount(Integer likeCount) { + this.likeCount = likeCount; + } } diff --git a/src/main/java/com/dailyon/snsservice/service/post/PostService.java b/src/main/java/com/dailyon/snsservice/service/post/PostService.java index bb01bee..44d9770 100644 --- a/src/main/java/com/dailyon/snsservice/service/post/PostService.java +++ b/src/main/java/com/dailyon/snsservice/service/post/PostService.java @@ -171,9 +171,7 @@ public PostLikePageResponse getPostLikes(Long memberId, Pageable pageable) { List modifiedPosts = new ArrayList<>(); - PostLikePageResponse postLikePageResponse = PostLikePageResponse.fromEntity(posts); - postLikePageResponse - .getPosts() + posts .forEach( post -> { try { @@ -189,6 +187,8 @@ public PostLikePageResponse getPostLikes(Long memberId, Pageable pageable) { // cache count 값으로 response를 업데이트 post.setViewCount(cachedPostCountVO.getViewCount()); post.setLikeCount(cachedPostCountVO.getLikeCount()); + + modifiedPosts.add(post); } catch (JsonProcessingException e) { throw new RuntimeException(e); } @@ -237,6 +237,9 @@ public OOTDPostPageResponse getMyOOTDPosts(Long memberId, Pageable pageable) { // cache count 값으로 response를 업데이트 OOTDPostResponse.setViewCount(cachedPostCountVO.getViewCount()); OOTDPostResponse.setLikeCount(cachedPostCountVO.getLikeCount()); + + // Add the modified PostResponse to the list + modifiedMyOOTDPostResponses.add(OOTDPostResponse); } catch (JsonProcessingException e) { throw new RuntimeException(e); } @@ -286,6 +289,9 @@ public OOTDPostPageResponse getMemberOOTDPosts( // cache count 값으로 response를 업데이트 OOTDPostResponse.setViewCount(cachedPostCountVO.getViewCount()); OOTDPostResponse.setLikeCount(cachedPostCountVO.getLikeCount()); + + // Add the modified PostResponse to the list + modifiedMemberOOTDPostResponses.add(OOTDPostResponse); } catch (JsonProcessingException e) { throw new RuntimeException(e); }