mirror of
https://github.com/nagisa77/OpenIsle.git
synced 2026-04-20 10:57:28 +08:00
Merge pull request #98 from nagisa77/codex/modify-/api/notifications-to-return-full-comment-data
Improve notification API response
This commit is contained in:
@@ -2,6 +2,8 @@ package com.openisle.controller;
|
|||||||
|
|
||||||
import com.openisle.model.Notification;
|
import com.openisle.model.Notification;
|
||||||
import com.openisle.model.NotificationType;
|
import com.openisle.model.NotificationType;
|
||||||
|
import com.openisle.model.Comment;
|
||||||
|
import com.openisle.model.Post;
|
||||||
import com.openisle.service.NotificationService;
|
import com.openisle.service.NotificationService;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
@@ -36,14 +38,46 @@ public class NotificationController {
|
|||||||
NotificationDto dto = new NotificationDto();
|
NotificationDto dto = new NotificationDto();
|
||||||
dto.setId(n.getId());
|
dto.setId(n.getId());
|
||||||
dto.setType(n.getType());
|
dto.setType(n.getType());
|
||||||
dto.setPostId(n.getPost() != null ? n.getPost().getId() : null);
|
if (n.getPost() != null) {
|
||||||
dto.setCommentId(n.getComment() != null ? n.getComment().getId() : null);
|
dto.setPost(toPostDto(n.getPost()));
|
||||||
|
}
|
||||||
|
if (n.getComment() != null) {
|
||||||
|
dto.setComment(toCommentDto(n.getComment()));
|
||||||
|
Comment parent = n.getComment().getParent();
|
||||||
|
if (parent != null) {
|
||||||
|
dto.setParentComment(toCommentDto(parent));
|
||||||
|
}
|
||||||
|
}
|
||||||
dto.setApproved(n.getApproved());
|
dto.setApproved(n.getApproved());
|
||||||
dto.setRead(n.isRead());
|
dto.setRead(n.isRead());
|
||||||
dto.setCreatedAt(n.getCreatedAt());
|
dto.setCreatedAt(n.getCreatedAt());
|
||||||
return dto;
|
return dto;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private PostDto toPostDto(Post post) {
|
||||||
|
PostDto dto = new PostDto();
|
||||||
|
dto.setId(post.getId());
|
||||||
|
dto.setTitle(post.getTitle());
|
||||||
|
return dto;
|
||||||
|
}
|
||||||
|
|
||||||
|
private CommentDto toCommentDto(Comment comment) {
|
||||||
|
CommentDto dto = new CommentDto();
|
||||||
|
dto.setId(comment.getId());
|
||||||
|
dto.setContent(comment.getContent());
|
||||||
|
dto.setCreatedAt(comment.getCreatedAt());
|
||||||
|
dto.setAuthor(toAuthorDto(comment.getAuthor()));
|
||||||
|
return dto;
|
||||||
|
}
|
||||||
|
|
||||||
|
private AuthorDto toAuthorDto(com.openisle.model.User user) {
|
||||||
|
AuthorDto dto = new AuthorDto();
|
||||||
|
dto.setId(user.getId());
|
||||||
|
dto.setUsername(user.getUsername());
|
||||||
|
dto.setAvatar(user.getAvatar());
|
||||||
|
return dto;
|
||||||
|
}
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
private static class MarkReadRequest {
|
private static class MarkReadRequest {
|
||||||
private List<Long> ids;
|
private List<Long> ids;
|
||||||
@@ -53,10 +87,32 @@ public class NotificationController {
|
|||||||
private static class NotificationDto {
|
private static class NotificationDto {
|
||||||
private Long id;
|
private Long id;
|
||||||
private NotificationType type;
|
private NotificationType type;
|
||||||
private Long postId;
|
private PostDto post;
|
||||||
private Long commentId;
|
private CommentDto comment;
|
||||||
|
private CommentDto parentComment;
|
||||||
private Boolean approved;
|
private Boolean approved;
|
||||||
private boolean read;
|
private boolean read;
|
||||||
private LocalDateTime createdAt;
|
private LocalDateTime createdAt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Data
|
||||||
|
private static class PostDto {
|
||||||
|
private Long id;
|
||||||
|
private String title;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Data
|
||||||
|
private static class CommentDto {
|
||||||
|
private Long id;
|
||||||
|
private String content;
|
||||||
|
private LocalDateTime createdAt;
|
||||||
|
private AuthorDto author;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Data
|
||||||
|
private static class AuthorDto {
|
||||||
|
private Long id;
|
||||||
|
private String username;
|
||||||
|
private String avatar;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user