Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.back.domain.post.post.dto.request.PostCreateRequestDto;
import com.back.domain.post.post.dto.request.PostSortScrollRequestDto;
import com.back.domain.post.post.dto.request.PostUpdateRequestDto;
import com.back.domain.post.post.dto.response.PostLikeResponseDto;
import com.back.domain.post.post.dto.response.PostResponseDto;
import com.back.domain.post.post.service.PostService;
import com.back.global.rsData.RsData;
Expand Down Expand Up @@ -114,10 +115,9 @@ public RsData<Void> deletePost(
*/
@PostMapping("/{postId}/like")
@Operation(summary = "게시글 추천")
public RsData<Void> toggleLike(
public RsData<PostLikeResponseDto> toggleLike(
@PathVariable Long postId
) {
postService.toggleLike(postId);
return RsData.successOf(null); // code=200, message="success"
return RsData.successOf(postService.toggleLike(postId)); // code=200, message="success"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.back.domain.post.post.dto.response;

import com.back.domain.post.post.entity.PostLike;
import com.back.domain.post.post.enums.PostLikeStatus;

public record PostLikeResponseDto(
PostLikeStatus status
) {

public PostLikeResponseDto(PostLike postLike) {
this(
postLike.getStatus()
);
}
}
23 changes: 14 additions & 9 deletions src/main/java/com/back/domain/post/post/service/PostService.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.back.domain.post.post.dto.request.PostCreateRequestDto;
import com.back.domain.post.post.dto.request.PostSortScrollRequestDto;
import com.back.domain.post.post.dto.request.PostUpdateRequestDto;
import com.back.domain.post.post.dto.response.PostLikeResponseDto;
import com.back.domain.post.post.dto.response.PostResponseDto;
import com.back.domain.post.post.entity.Post;
import com.back.domain.post.post.entity.PostImage;
Expand Down Expand Up @@ -233,7 +234,7 @@ public void deletePost(Long postId) {

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

Post post = postRepository.findById(postId)
Expand All @@ -248,6 +249,8 @@ public void toggleLike(Long postId) {
post.decreaseLikeCount();
// 활동 점수: 추천 취소 시 -0.1
abvScoreService.revokeForLike(user.getId());

return new PostLikeResponseDto(existingLike.get().getStatus());
} else {
// 추천 추가
PostLike postLike = PostLike.builder()
Expand All @@ -259,15 +262,17 @@ public void toggleLike(Long postId) {
post.increaseLikeCount();
// 활동 점수: 추천 추가 시 +0.1
abvScoreService.awardForLike(user.getId());
}

// 게시글 작성자에게 알림 전송
notificationService.sendNotification(
post.getUser(),
post,
NotificationType.LIKE,
user.getNickname() + " 님이 추천을 남겼습니다."
);
// 게시글 작성자에게 알림 전송
notificationService.sendNotification(
post.getUser(),
post,
NotificationType.LIKE,
user.getNickname() + " 님이 추천을 남겼습니다."
);

return new PostLikeResponseDto(postLike.getStatus());
}
}

// 태그 추가 메서드
Expand Down