Skip to content

Commit

Permalink
Merge pull request #160 from IT-Cotato/refactor/156
Browse files Browse the repository at this point in the history
[Bugfix] 이미 Trending 게시판에 있는 게시글은 좋아요 더 늘어도 추가되지 않도록 수정
  • Loading branch information
u-genuine authored Feb 21, 2025
2 parents b00ad7f + dba5760 commit 32f7d2e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public class PostDeleter {
private final PostFinder postFinder;
private final PostDraftRepository postDraftRepository;
private final TrendingPostRepository trendingPostRepository;
private static final int TRENDING_LIKE_THRESHOLD = 3;


@Transactional
public void delete(Long postId) {
Expand All @@ -50,7 +52,7 @@ public void deletePostsByBoardIds(List<Long> boardIds) {
public void deleteTrendingPost(Long postId) {
Post post = postFinder.getPost(postId);

if (post.getLikes() < 10) {
if (post.getLikes() == TRENDING_LIKE_THRESHOLD) {
trendingPostRepository.deleteByPostId(postId);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,11 +326,12 @@ public void likePost(Long postId) {
// 3. 좋아요 추가
postLikeUpdater.appendPostLike(postId, userId);

// 4. post의 likes + 1
// 4. 기존에 좋아요가 2개였다면 Trending 게시판에 추가
trendingPostAppender.appendTrendingPost(postId);

// 5. post의 likes + 1
postUpdater.increasePostLike(postId);

// 5. Trending 게시판 조건 만족 시 추가
trendingPostAppender.appendTrendingPost(postId);
}

@Transactional
Expand All @@ -341,11 +342,12 @@ public void unlikePost(Long postId) {
// 2. 좋아요 삭제
postLikeUpdater.deletePostLike(postId, userId);

// 4. 기존에 좋아요가 3개 였다면 Trending 게시판에서 제거
postDeleter.deleteTrendingPost(postId);

// 3. post의 likes - 1
postUpdater.decreasePostLike(postId);

// 4. 좋아요 10개 미만될 경우 Trending 게시판에서 제거
postDeleter.deleteTrendingPost(postId);
}

public Slice<MyPostWithPhoto> findUserPosts(int page) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ public class TrendingPostAppender {
private final TrendingPostRepository trendingPostRepository;
private final PostFinder postFinder;

private static final int TRENDING_LIKE_THRESHOLD = 3;

@Transactional
public void appendTrendingPost(Long postId) {
Post post = postFinder.getPost(postId);

if (post.getLikes() >= 3) {
if (post.getLikes() == TRENDING_LIKE_THRESHOLD - 1) {
TrendingPost trendingPost = TrendingPost.builder()
.postId(postId)
.boardId(post.getBoardId())
Expand Down

0 comments on commit 32f7d2e

Please sign in to comment.