Skip to content

Commit 9b4d92e

Browse files
committed
feat: 게시글 작성/삭제, 좋아요 활동 점수 반영
1 parent 78c3c5d commit 9b4d92e

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/main/java/com/back/domain/post/post/service/PostService.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import com.back.domain.post.post.repository.TagRepository;
1818
import com.back.domain.user.entity.User;
1919
import com.back.global.rq.Rq;
20+
import com.back.domain.user.service.AbvScoreService;
2021
import java.util.List;
2122
import java.util.NoSuchElementException;
2223
import java.util.Optional;
@@ -35,6 +36,7 @@ public class PostService {
3536
private final PostLikeRepository postLikeRepository;
3637
private final NotificationService notificationService;
3738
private final Rq rq;
39+
private final AbvScoreService abvScoreService;
3840

3941
// 게시글 작성 로직
4042
@Transactional
@@ -58,7 +60,10 @@ public PostResponseDto createPost(PostCreateRequestDto reqBody) {
5860
addTag(tagNames, post);
5961
}
6062

61-
return new PostResponseDto(postRepository.save(post));
63+
Post saved = postRepository.save(post);
64+
// 활동 점수: 게시글 작성 +0.5
65+
abvScoreService.awardForPost(user.getId());
66+
return new PostResponseDto(saved);
6267
}
6368

6469
// 게시글 다건 조회 로직
@@ -136,6 +141,8 @@ public void deletePost(Long postId) {
136141
.orElseThrow(() -> new NoSuchElementException("해당 게시글을 찾을 수 없습니다. ID: " + postId));
137142

138143
post.updateStatus(PostStatus.DELETED);
144+
// 활동 점수: 게시글 삭제 시 -0.5 (작성자 기준)
145+
abvScoreService.revokeForPost(post.getUser().getId());
139146

140147
// soft delete를 사용하기 위해 레포지토리 삭제 작업은 진행하지 않음.
141148
// postRepository.delete(post);
@@ -156,6 +163,8 @@ public void toggleLike(Long postId) {
156163
existingLike.get().updateStatus(PostLikeStatus.NONE);
157164
postLikeRepository.delete(existingLike.get());
158165
post.decreaseLikeCount();
166+
// 활동 점수: 추천 취소 시 -0.1
167+
abvScoreService.revokeForLike(user.getId());
159168
} else {
160169
// 추천 추가
161170
PostLike postLike = PostLike.builder()
@@ -165,6 +174,8 @@ public void toggleLike(Long postId) {
165174
.build();
166175
postLikeRepository.save(postLike);
167176
post.increaseLikeCount();
177+
// 활동 점수: 추천 추가 시 +0.1
178+
abvScoreService.awardForLike(user.getId());
168179
}
169180

170181
// 게시글 작성자에게 알림 전송

0 commit comments

Comments
 (0)