Skip to content

Commit 85003be

Browse files
authored
[fix] 게시글 추천 시 프론트에서 여부를 확인할 수 있도록 api 수정#280
[fix] 게시글 추천 시 프론트에서 여부를 확인할 수 있도록 api 수정#280
2 parents d290ff0 + 6d75048 commit 85003be

File tree

3 files changed

+32
-12
lines changed

3 files changed

+32
-12
lines changed

src/main/java/com/back/domain/post/post/controller/PostController.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.back.domain.post.post.dto.request.PostCreateRequestDto;
44
import com.back.domain.post.post.dto.request.PostSortScrollRequestDto;
55
import com.back.domain.post.post.dto.request.PostUpdateRequestDto;
6+
import com.back.domain.post.post.dto.response.PostLikeResponseDto;
67
import com.back.domain.post.post.dto.response.PostResponseDto;
78
import com.back.domain.post.post.service.PostService;
89
import com.back.global.rsData.RsData;
@@ -114,10 +115,9 @@ public RsData<Void> deletePost(
114115
*/
115116
@PostMapping("/{postId}/like")
116117
@Operation(summary = "게시글 추천")
117-
public RsData<Void> toggleLike(
118+
public RsData<PostLikeResponseDto> toggleLike(
118119
@PathVariable Long postId
119120
) {
120-
postService.toggleLike(postId);
121-
return RsData.successOf(null); // code=200, message="success"
121+
return RsData.successOf(postService.toggleLike(postId)); // code=200, message="success"
122122
}
123123
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.back.domain.post.post.dto.response;
2+
3+
import com.back.domain.post.post.entity.PostLike;
4+
import com.back.domain.post.post.enums.PostLikeStatus;
5+
6+
public record PostLikeResponseDto(
7+
PostLikeStatus status
8+
) {
9+
10+
public PostLikeResponseDto(PostLike postLike) {
11+
this(
12+
postLike.getStatus()
13+
);
14+
}
15+
}

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

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import com.back.domain.post.post.dto.request.PostCreateRequestDto;
88
import com.back.domain.post.post.dto.request.PostSortScrollRequestDto;
99
import com.back.domain.post.post.dto.request.PostUpdateRequestDto;
10+
import com.back.domain.post.post.dto.response.PostLikeResponseDto;
1011
import com.back.domain.post.post.dto.response.PostResponseDto;
1112
import com.back.domain.post.post.entity.Post;
1213
import com.back.domain.post.post.entity.PostImage;
@@ -233,7 +234,7 @@ public void deletePost(Long postId) {
233234

234235
// 게시글 추천(좋아요) 토글 로직
235236
@Transactional
236-
public void toggleLike(Long postId) {
237+
public PostLikeResponseDto toggleLike(Long postId) {
237238
User user = rq.getActor(); // 현재 로그인한 사용자
238239

239240
Post post = postRepository.findById(postId)
@@ -248,6 +249,8 @@ public void toggleLike(Long postId) {
248249
post.decreaseLikeCount();
249250
// 활동 점수: 추천 취소 시 -0.1
250251
abvScoreService.revokeForLike(user.getId());
252+
253+
return new PostLikeResponseDto(existingLike.get().getStatus());
251254
} else {
252255
// 추천 추가
253256
PostLike postLike = PostLike.builder()
@@ -259,15 +262,17 @@ public void toggleLike(Long postId) {
259262
post.increaseLikeCount();
260263
// 활동 점수: 추천 추가 시 +0.1
261264
abvScoreService.awardForLike(user.getId());
262-
}
263265

264-
// 게시글 작성자에게 알림 전송
265-
notificationService.sendNotification(
266-
post.getUser(),
267-
post,
268-
NotificationType.LIKE,
269-
user.getNickname() + " 님이 추천을 남겼습니다."
270-
);
266+
// 게시글 작성자에게 알림 전송
267+
notificationService.sendNotification(
268+
post.getUser(),
269+
post,
270+
NotificationType.LIKE,
271+
user.getNickname() + " 님이 추천을 남겼습니다."
272+
);
273+
274+
return new PostLikeResponseDto(postLike.getStatus());
275+
}
271276
}
272277

273278
// 태그 추가 메서드

0 commit comments

Comments
 (0)