mirror of
https://github.com/nagisa77/OpenIsle.git
synced 2026-02-22 06:50:53 +08:00
feat: implement post subscription notifications
This commit is contained in:
@@ -8,6 +8,7 @@ import com.openisle.service.PostService;
|
||||
import com.openisle.service.ReactionService;
|
||||
import com.openisle.service.CaptchaService;
|
||||
import com.openisle.service.DraftService;
|
||||
import com.openisle.service.SubscriptionService;
|
||||
import lombok.Data;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
@@ -26,6 +27,7 @@ public class PostController {
|
||||
private final PostService postService;
|
||||
private final CommentService commentService;
|
||||
private final ReactionService reactionService;
|
||||
private final SubscriptionService subscriptionService;
|
||||
private final CaptchaService captchaService;
|
||||
private final DraftService draftService;
|
||||
|
||||
@@ -50,7 +52,7 @@ public class PostController {
|
||||
public ResponseEntity<PostDto> getPost(@PathVariable Long id, Authentication auth) {
|
||||
String viewer = auth != null ? auth.getName() : null;
|
||||
Post post = postService.viewPost(id, viewer);
|
||||
return ResponseEntity.ok(toDto(post));
|
||||
return ResponseEntity.ok(toDto(post, viewer));
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
@@ -134,6 +136,16 @@ public class PostController {
|
||||
return dto;
|
||||
}
|
||||
|
||||
private PostDto toDto(Post post, String viewer) {
|
||||
PostDto dto = toDto(post);
|
||||
if (viewer != null) {
|
||||
dto.setSubscribed(subscriptionService.isPostSubscribed(viewer, post.getId()));
|
||||
} else {
|
||||
dto.setSubscribed(false);
|
||||
}
|
||||
return dto;
|
||||
}
|
||||
|
||||
private CommentDto toCommentDtoWithReplies(Comment comment) {
|
||||
CommentDto dto = toCommentDto(comment);
|
||||
List<CommentDto> replies = commentService.getReplies(comment.getId()).stream()
|
||||
@@ -223,6 +235,7 @@ public class PostController {
|
||||
private List<CommentDto> comments;
|
||||
private List<ReactionDto> reactions;
|
||||
private java.util.List<AuthorDto> participants;
|
||||
private boolean subscribed;
|
||||
}
|
||||
|
||||
@Data
|
||||
|
||||
Reference in New Issue
Block a user