mirror of https://github.com/halo-dev/halo
Rename comment to post comment
parent
c9bfd11cd5
commit
c3985cf9c5
|
@ -32,7 +32,7 @@ public class AdminController {
|
||||||
|
|
||||||
private final AttachmentService attachmentService;
|
private final AttachmentService attachmentService;
|
||||||
|
|
||||||
private final CommentService commentService;
|
private final PostCommentService postCommentService;
|
||||||
|
|
||||||
private final OptionService optionService;
|
private final OptionService optionService;
|
||||||
|
|
||||||
|
@ -42,13 +42,13 @@ public class AdminController {
|
||||||
|
|
||||||
public AdminController(PostService postService,
|
public AdminController(PostService postService,
|
||||||
AttachmentService attachmentService,
|
AttachmentService attachmentService,
|
||||||
CommentService commentService,
|
PostCommentService postCommentService,
|
||||||
OptionService optionService,
|
OptionService optionService,
|
||||||
UserService userService,
|
UserService userService,
|
||||||
LinkService linkService) {
|
LinkService linkService) {
|
||||||
this.postService = postService;
|
this.postService = postService;
|
||||||
this.attachmentService = attachmentService;
|
this.attachmentService = attachmentService;
|
||||||
this.commentService = commentService;
|
this.postCommentService = postCommentService;
|
||||||
this.optionService = optionService;
|
this.optionService = optionService;
|
||||||
this.userService = userService;
|
this.userService = userService;
|
||||||
this.linkService = linkService;
|
this.linkService = linkService;
|
||||||
|
@ -65,7 +65,7 @@ public class AdminController {
|
||||||
CountDTO countDTO = new CountDTO();
|
CountDTO countDTO = new CountDTO();
|
||||||
countDTO.setPostCount(postService.countByStatus(PostStatus.PUBLISHED));
|
countDTO.setPostCount(postService.countByStatus(PostStatus.PUBLISHED));
|
||||||
countDTO.setAttachmentCount(attachmentService.count());
|
countDTO.setAttachmentCount(attachmentService.count());
|
||||||
countDTO.setCommentCount(commentService.count());
|
countDTO.setCommentCount(postCommentService.count());
|
||||||
|
|
||||||
long currentTimeMillis = System.currentTimeMillis();
|
long currentTimeMillis = System.currentTimeMillis();
|
||||||
|
|
||||||
|
|
|
@ -1,82 +0,0 @@
|
||||||
package run.halo.app.controller.admin.api;
|
|
||||||
|
|
||||||
import io.swagger.annotations.ApiOperation;
|
|
||||||
import org.springframework.data.domain.Page;
|
|
||||||
import org.springframework.data.domain.Pageable;
|
|
||||||
import org.springframework.data.web.PageableDefault;
|
|
||||||
import org.springframework.web.bind.annotation.*;
|
|
||||||
import run.halo.app.model.dto.BaseCommentDTO;
|
|
||||||
import run.halo.app.model.entity.Comment;
|
|
||||||
import run.halo.app.model.enums.CommentStatus;
|
|
||||||
import run.halo.app.model.params.CommentParam;
|
|
||||||
import run.halo.app.model.params.CommentQuery;
|
|
||||||
import run.halo.app.model.vo.CommentWithPostVO;
|
|
||||||
import run.halo.app.service.CommentService;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import static org.springframework.data.domain.Sort.Direction.DESC;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Comment controller.
|
|
||||||
*
|
|
||||||
* @author johnniang
|
|
||||||
* @date 3/19/19
|
|
||||||
*/
|
|
||||||
@RestController
|
|
||||||
@RequestMapping("/api/admin/comments")
|
|
||||||
public class CommentController {
|
|
||||||
|
|
||||||
private final CommentService commentService;
|
|
||||||
|
|
||||||
public CommentController(CommentService commentService) {
|
|
||||||
this.commentService = commentService;
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping
|
|
||||||
@ApiOperation("Lists comments")
|
|
||||||
public Page<CommentWithPostVO> pageBy(@PageableDefault(sort = "updateTime", direction = DESC) Pageable pageable,
|
|
||||||
CommentQuery commentQuery) {
|
|
||||||
Page<Comment> commentPage = commentService.pageBy(commentQuery, pageable);
|
|
||||||
return commentService.convertToWithPostVo(commentPage);
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping("latest")
|
|
||||||
@ApiOperation("Pages latest comments")
|
|
||||||
public List<CommentWithPostVO> pageLatest(@RequestParam(name = "top", defaultValue = "10") int top) {
|
|
||||||
List<Comment> content = commentService.pageLatest(top).getContent();
|
|
||||||
return commentService.convertToWithPostVo(content);
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping("status/{status}")
|
|
||||||
public Page<CommentWithPostVO> pageBy(@PageableDefault(sort = "updateTime", direction = DESC) Pageable pageable,
|
|
||||||
@PathVariable("status") CommentStatus status) {
|
|
||||||
Page<Comment> commentPage = commentService.pageBy(status, pageable);
|
|
||||||
return commentService.convertToWithPostVo(commentPage);
|
|
||||||
}
|
|
||||||
|
|
||||||
@PostMapping
|
|
||||||
@ApiOperation("Creates a comment (new or reply)")
|
|
||||||
public BaseCommentDTO createBy(@RequestBody CommentParam commentParam) {
|
|
||||||
Comment createdComment = commentService.createBy(commentParam);
|
|
||||||
return commentService.convertTo(createdComment);
|
|
||||||
}
|
|
||||||
|
|
||||||
@PutMapping("{commentId:\\d+}/status/{status}")
|
|
||||||
@ApiOperation("Updates comment status")
|
|
||||||
public BaseCommentDTO updateStatusBy(@PathVariable("commentId") Long commentId,
|
|
||||||
@PathVariable("status") CommentStatus status) {
|
|
||||||
// Update comment status
|
|
||||||
Comment updatedComment = commentService.updateStatus(commentId, status);
|
|
||||||
|
|
||||||
return commentService.convertTo(updatedComment);
|
|
||||||
}
|
|
||||||
|
|
||||||
@DeleteMapping("{commentId:\\d+}")
|
|
||||||
@ApiOperation("Deletes comment permanently and recursively")
|
|
||||||
public BaseCommentDTO deleteBy(@PathVariable("commentId") Long commentId) {
|
|
||||||
Comment deletedComment = commentService.removeById(commentId);
|
|
||||||
|
|
||||||
return commentService.convertTo(deletedComment);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,75 @@
|
||||||
|
package run.halo.app.controller.admin.api;
|
||||||
|
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import org.springframework.data.domain.Page;
|
||||||
|
import org.springframework.data.domain.Pageable;
|
||||||
|
import org.springframework.data.web.PageableDefault;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import run.halo.app.model.dto.BaseCommentDTO;
|
||||||
|
import run.halo.app.model.entity.PostComment;
|
||||||
|
import run.halo.app.model.enums.CommentStatus;
|
||||||
|
import run.halo.app.model.params.CommentParam;
|
||||||
|
import run.halo.app.model.params.CommentQuery;
|
||||||
|
import run.halo.app.model.vo.PostCommentWithPostVO;
|
||||||
|
import run.halo.app.service.PostCommentService;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.springframework.data.domain.Sort.Direction.DESC;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Post comment controller.
|
||||||
|
*
|
||||||
|
* @author johnniang
|
||||||
|
* @date 3/19/19
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api/admin/posts/comments")
|
||||||
|
public class PostCommentController {
|
||||||
|
|
||||||
|
private final PostCommentService postCommentService;
|
||||||
|
|
||||||
|
public PostCommentController(PostCommentService postCommentService) {
|
||||||
|
this.postCommentService = postCommentService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping
|
||||||
|
@ApiOperation("Lists comments")
|
||||||
|
public Page<PostCommentWithPostVO> pageBy(@PageableDefault(sort = "updateTime", direction = DESC) Pageable pageable,
|
||||||
|
CommentQuery commentQuery) {
|
||||||
|
Page<PostComment> commentPage = postCommentService.pageBy(commentQuery, pageable);
|
||||||
|
return postCommentService.convertToWithPostVo(commentPage);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("latest")
|
||||||
|
@ApiOperation("Pages latest comments")
|
||||||
|
public List<PostCommentWithPostVO> pageLatest(@RequestParam(name = "top", defaultValue = "10") int top) {
|
||||||
|
List<PostComment> content = postCommentService.pageLatest(top).getContent();
|
||||||
|
return postCommentService.convertToWithPostVo(content);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping
|
||||||
|
@ApiOperation("Creates a comment (new or reply)")
|
||||||
|
public BaseCommentDTO createBy(@RequestBody CommentParam commentParam) {
|
||||||
|
PostComment createdPostComment = postCommentService.createBy(commentParam);
|
||||||
|
return postCommentService.convertTo(createdPostComment);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PutMapping("{commentId:\\d+}/status/{status}")
|
||||||
|
@ApiOperation("Updates comment status")
|
||||||
|
public BaseCommentDTO updateStatusBy(@PathVariable("commentId") Long commentId,
|
||||||
|
@PathVariable("status") CommentStatus status) {
|
||||||
|
// Update comment status
|
||||||
|
PostComment updatedPostComment = postCommentService.updateStatus(commentId, status);
|
||||||
|
|
||||||
|
return postCommentService.convertTo(updatedPostComment);
|
||||||
|
}
|
||||||
|
|
||||||
|
@DeleteMapping("{commentId:\\d+}")
|
||||||
|
@ApiOperation("Deletes comment permanently and recursively")
|
||||||
|
public BaseCommentDTO deleteBy(@PathVariable("commentId") Long commentId) {
|
||||||
|
PostComment deletedPostComment = postCommentService.removeById(commentId);
|
||||||
|
|
||||||
|
return postCommentService.convertTo(deletedPostComment);
|
||||||
|
}
|
||||||
|
}
|
|
@ -36,20 +36,12 @@ public class PostController {
|
||||||
|
|
||||||
private final PostTagService postTagService;
|
private final PostTagService postTagService;
|
||||||
|
|
||||||
private final CommentService commentService;
|
|
||||||
|
|
||||||
private final OptionService optionService;
|
|
||||||
|
|
||||||
public PostController(PostService postService,
|
public PostController(PostService postService,
|
||||||
PostCategoryService postCategoryService,
|
PostCategoryService postCategoryService,
|
||||||
PostTagService postTagService,
|
PostTagService postTagService) {
|
||||||
CommentService commentService,
|
|
||||||
OptionService optionService) {
|
|
||||||
this.postService = postService;
|
this.postService = postService;
|
||||||
this.postCategoryService = postCategoryService;
|
this.postCategoryService = postCategoryService;
|
||||||
this.postTagService = postTagService;
|
this.postTagService = postTagService;
|
||||||
this.commentService = commentService;
|
|
||||||
this.optionService = optionService;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping
|
@GetMapping
|
||||||
|
|
|
@ -38,7 +38,7 @@ public class ContentArchiveController {
|
||||||
|
|
||||||
private final PostService postService;
|
private final PostService postService;
|
||||||
|
|
||||||
private final CommentService commentService;
|
private final PostCommentService postCommentService;
|
||||||
|
|
||||||
private final ThemeService themeService;
|
private final ThemeService themeService;
|
||||||
|
|
||||||
|
@ -49,13 +49,13 @@ public class ContentArchiveController {
|
||||||
private final OptionService optionService;
|
private final OptionService optionService;
|
||||||
|
|
||||||
public ContentArchiveController(PostService postService,
|
public ContentArchiveController(PostService postService,
|
||||||
CommentService commentService,
|
PostCommentService postCommentService,
|
||||||
ThemeService themeService,
|
ThemeService themeService,
|
||||||
PostCategoryService postCategoryService,
|
PostCategoryService postCategoryService,
|
||||||
PostTagService postTagService,
|
PostTagService postTagService,
|
||||||
OptionService optionService) {
|
OptionService optionService) {
|
||||||
this.postService = postService;
|
this.postService = postService;
|
||||||
this.commentService = commentService;
|
this.postCommentService = postCommentService;
|
||||||
this.themeService = themeService;
|
this.themeService = themeService;
|
||||||
this.postCategoryService = postCategoryService;
|
this.postCategoryService = postCategoryService;
|
||||||
this.postTagService = postTagService;
|
this.postTagService = postTagService;
|
||||||
|
@ -116,7 +116,7 @@ public class ContentArchiveController {
|
||||||
List<Category> categories = postCategoryService.listCategoryBy(post.getId());
|
List<Category> categories = postCategoryService.listCategoryBy(post.getId());
|
||||||
List<Tag> tags = postTagService.listTagsBy(post.getId());
|
List<Tag> tags = postTagService.listTagsBy(post.getId());
|
||||||
|
|
||||||
Page<BaseCommentVO> comments = commentService.pageVosBy(post.getId(), PageRequest.of(cp, optionService.getCommentPageSize(), sort));
|
Page<BaseCommentVO> comments = postCommentService.pageVosBy(post.getId(), PageRequest.of(cp, optionService.getCommentPageSize(), sort));
|
||||||
final int[] pageRainbow = PageUtil.rainbow(cp, comments.getTotalPages(), 3);
|
final int[] pageRainbow = PageUtil.rainbow(cp, comments.getTotalPages(), 3);
|
||||||
|
|
||||||
model.addAttribute("is_post", true);
|
model.addAttribute("is_post", true);
|
||||||
|
|
|
@ -8,7 +8,7 @@ import org.springframework.web.bind.annotation.PathVariable;
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
import run.halo.app.model.entity.Sheet;
|
import run.halo.app.model.entity.Sheet;
|
||||||
import run.halo.app.model.enums.PostStatus;
|
import run.halo.app.model.enums.PostStatus;
|
||||||
import run.halo.app.service.CommentService;
|
import run.halo.app.service.PostCommentService;
|
||||||
import run.halo.app.service.SheetService;
|
import run.halo.app.service.SheetService;
|
||||||
import run.halo.app.service.ThemeService;
|
import run.halo.app.service.ThemeService;
|
||||||
|
|
||||||
|
@ -22,15 +22,15 @@ public class ContentSheetController {
|
||||||
|
|
||||||
private final SheetService sheetService;
|
private final SheetService sheetService;
|
||||||
|
|
||||||
private final CommentService commentService;
|
private final PostCommentService postCommentService;
|
||||||
|
|
||||||
private final ThemeService themeService;
|
private final ThemeService themeService;
|
||||||
|
|
||||||
public ContentSheetController(SheetService sheetService,
|
public ContentSheetController(SheetService sheetService,
|
||||||
CommentService commentService,
|
PostCommentService postCommentService,
|
||||||
ThemeService themeService) {
|
ThemeService themeService) {
|
||||||
this.sheetService = sheetService;
|
this.sheetService = sheetService;
|
||||||
this.commentService = commentService;
|
this.postCommentService = postCommentService;
|
||||||
this.themeService = themeService;
|
this.themeService = themeService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
import run.halo.app.model.dto.BaseCommentDTO;
|
import run.halo.app.model.dto.BaseCommentDTO;
|
||||||
import run.halo.app.model.params.CommentParam;
|
import run.halo.app.model.params.CommentParam;
|
||||||
import run.halo.app.service.CommentService;
|
import run.halo.app.service.PostCommentService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Portal comment controller.
|
* Portal comment controller.
|
||||||
|
@ -19,15 +19,15 @@ import run.halo.app.service.CommentService;
|
||||||
@RequestMapping("/api/comments")
|
@RequestMapping("/api/comments")
|
||||||
public class CommentController {
|
public class CommentController {
|
||||||
|
|
||||||
private final CommentService commentService;
|
private final PostCommentService postCommentService;
|
||||||
|
|
||||||
public CommentController(CommentService commentService) {
|
public CommentController(PostCommentService postCommentService) {
|
||||||
this.commentService = commentService;
|
this.postCommentService = postCommentService;
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping
|
@PostMapping
|
||||||
@ApiOperation("Comments a post")
|
@ApiOperation("Comments a post")
|
||||||
public BaseCommentDTO comment(@RequestBody CommentParam commentParam) {
|
public BaseCommentDTO comment(@RequestBody CommentParam commentParam) {
|
||||||
return commentService.convertTo(commentService.createBy(commentParam));
|
return postCommentService.convertTo(postCommentService.createBy(commentParam));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@ import run.halo.app.model.dto.post.PostSimpleDTO;
|
||||||
import run.halo.app.model.enums.PostStatus;
|
import run.halo.app.model.enums.PostStatus;
|
||||||
import run.halo.app.model.vo.BaseCommentVO;
|
import run.halo.app.model.vo.BaseCommentVO;
|
||||||
import run.halo.app.model.vo.BaseCommentWithParentVO;
|
import run.halo.app.model.vo.BaseCommentWithParentVO;
|
||||||
import run.halo.app.service.CommentService;
|
import run.halo.app.service.PostCommentService;
|
||||||
import run.halo.app.service.OptionService;
|
import run.halo.app.service.OptionService;
|
||||||
import run.halo.app.service.PostService;
|
import run.halo.app.service.PostService;
|
||||||
|
|
||||||
|
@ -31,15 +31,15 @@ public class PostController {
|
||||||
|
|
||||||
private final PostService postService;
|
private final PostService postService;
|
||||||
|
|
||||||
private final CommentService commentService;
|
private final PostCommentService postCommentService;
|
||||||
|
|
||||||
private final OptionService optionService;
|
private final OptionService optionService;
|
||||||
|
|
||||||
public PostController(PostService postService,
|
public PostController(PostService postService,
|
||||||
CommentService commentService,
|
PostCommentService postCommentService,
|
||||||
OptionService optionService) {
|
OptionService optionService) {
|
||||||
this.postService = postService;
|
this.postService = postService;
|
||||||
this.commentService = commentService;
|
this.postCommentService = postCommentService;
|
||||||
this.optionService = optionService;
|
this.optionService = optionService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,7 +74,7 @@ public class PostController {
|
||||||
public Page<BaseCommentVO> listCommentsTree(@PathVariable("postId") Integer postId,
|
public Page<BaseCommentVO> listCommentsTree(@PathVariable("postId") Integer postId,
|
||||||
@RequestParam(name = "page", required = false, defaultValue = "0") int page,
|
@RequestParam(name = "page", required = false, defaultValue = "0") int page,
|
||||||
@SortDefault(sort = "createTime", direction = DESC) Sort sort) {
|
@SortDefault(sort = "createTime", direction = DESC) Sort sort) {
|
||||||
return commentService.pageVosBy(postId, PageRequest.of(page, optionService.getCommentPageSize(), sort));
|
return postCommentService.pageVosBy(postId, PageRequest.of(page, optionService.getCommentPageSize(), sort));
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("{postId:\\d+}/comments/list_view")
|
@GetMapping("{postId:\\d+}/comments/list_view")
|
||||||
|
@ -82,7 +82,7 @@ public class PostController {
|
||||||
public Page<BaseCommentWithParentVO> listComments(@PathVariable("postId") Integer postId,
|
public Page<BaseCommentWithParentVO> listComments(@PathVariable("postId") Integer postId,
|
||||||
@RequestParam(name = "page", required = false, defaultValue = "0") int page,
|
@RequestParam(name = "page", required = false, defaultValue = "0") int page,
|
||||||
@SortDefault(sort = "createTime", direction = DESC) Sort sort) {
|
@SortDefault(sort = "createTime", direction = DESC) Sort sort) {
|
||||||
return commentService.pageWithParentVoBy(postId, PageRequest.of(page, optionService.getCommentPageSize(), sort));
|
return postCommentService.pageWithParentVoBy(postId, PageRequest.of(page, optionService.getCommentPageSize(), sort));
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("{postId:\\d+}/likes")
|
@PostMapping("{postId:\\d+}/likes")
|
||||||
|
|
|
@ -43,7 +43,7 @@ public class InstallController {
|
||||||
|
|
||||||
private final PostService postService;
|
private final PostService postService;
|
||||||
|
|
||||||
private final CommentService commentService;
|
private final PostCommentService postCommentService;
|
||||||
|
|
||||||
private final OptionService optionService;
|
private final OptionService optionService;
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@ public class InstallController {
|
||||||
public InstallController(UserService userService,
|
public InstallController(UserService userService,
|
||||||
CategoryService categoryService,
|
CategoryService categoryService,
|
||||||
PostService postService,
|
PostService postService,
|
||||||
CommentService commentService,
|
PostCommentService postCommentService,
|
||||||
OptionService optionService,
|
OptionService optionService,
|
||||||
MenuService menuService,
|
MenuService menuService,
|
||||||
Configuration configuration,
|
Configuration configuration,
|
||||||
|
@ -64,7 +64,7 @@ public class InstallController {
|
||||||
this.userService = userService;
|
this.userService = userService;
|
||||||
this.categoryService = categoryService;
|
this.categoryService = categoryService;
|
||||||
this.postService = postService;
|
this.postService = postService;
|
||||||
this.commentService = commentService;
|
this.postCommentService = postCommentService;
|
||||||
this.optionService = optionService;
|
this.optionService = optionService;
|
||||||
this.menuService = menuService;
|
this.menuService = menuService;
|
||||||
this.configuration = configuration;
|
this.configuration = configuration;
|
||||||
|
@ -115,8 +115,8 @@ public class InstallController {
|
||||||
// Create default post
|
// Create default post
|
||||||
Post post = createDefaultPost(category);
|
Post post = createDefaultPost(category);
|
||||||
|
|
||||||
// Create default comment
|
// Create default postComment
|
||||||
Comment comment = createDefaultComment();
|
PostComment postComment = createDefaultComment();
|
||||||
|
|
||||||
// Create default menu
|
// Create default menu
|
||||||
createDefaultMenu();
|
createDefaultMenu();
|
||||||
|
@ -149,7 +149,7 @@ public class InstallController {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private Comment createDefaultComment() {
|
private PostComment createDefaultComment() {
|
||||||
// TODO Create default comment
|
// TODO Create default comment
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ import org.springframework.lang.NonNull;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Comment new event.
|
* PostComment new event.
|
||||||
*
|
*
|
||||||
* @author johnniang
|
* @author johnniang
|
||||||
* @date 19-4-23
|
* @date 19-4-23
|
||||||
|
@ -13,7 +13,7 @@ import org.springframework.util.Assert;
|
||||||
public abstract class CommentBaseEvent extends ApplicationEvent {
|
public abstract class CommentBaseEvent extends ApplicationEvent {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Comment id.
|
* PostComment id.
|
||||||
*/
|
*/
|
||||||
private final Long commentId;
|
private final Long commentId;
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ public abstract class CommentBaseEvent extends ApplicationEvent {
|
||||||
public CommentBaseEvent(Object source, @NonNull Long commentId) {
|
public CommentBaseEvent(Object source, @NonNull Long commentId) {
|
||||||
super(source);
|
super(source);
|
||||||
|
|
||||||
Assert.notNull(commentId, "Comment id must not be null");
|
Assert.notNull(commentId, "PostComment id must not be null");
|
||||||
this.commentId = commentId;
|
this.commentId = commentId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ import org.springframework.context.event.EventListener;
|
||||||
import org.springframework.scheduling.annotation.Async;
|
import org.springframework.scheduling.annotation.Async;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import run.halo.app.exception.ServiceException;
|
import run.halo.app.exception.ServiceException;
|
||||||
import run.halo.app.model.entity.Comment;
|
import run.halo.app.model.entity.PostComment;
|
||||||
import run.halo.app.model.entity.Post;
|
import run.halo.app.model.entity.Post;
|
||||||
import run.halo.app.model.entity.User;
|
import run.halo.app.model.entity.User;
|
||||||
import run.halo.app.model.properties.BlogProperties;
|
import run.halo.app.model.properties.BlogProperties;
|
||||||
|
@ -17,7 +17,7 @@ import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Comment event listener.
|
* PostComment event listener.
|
||||||
*
|
*
|
||||||
* @author johnniang
|
* @author johnniang
|
||||||
* @date 19-4-23
|
* @date 19-4-23
|
||||||
|
@ -30,7 +30,7 @@ public class CommentEventListener {
|
||||||
|
|
||||||
private final OptionService optionService;
|
private final OptionService optionService;
|
||||||
|
|
||||||
private final CommentService commentService;
|
private final PostCommentService postCommentService;
|
||||||
|
|
||||||
private final PostService postService;
|
private final PostService postService;
|
||||||
|
|
||||||
|
@ -38,12 +38,12 @@ public class CommentEventListener {
|
||||||
|
|
||||||
public CommentEventListener(MailService mailService,
|
public CommentEventListener(MailService mailService,
|
||||||
OptionService optionService,
|
OptionService optionService,
|
||||||
CommentService commentService,
|
PostCommentService postCommentService,
|
||||||
PostService postService,
|
PostService postService,
|
||||||
UserService userService) {
|
UserService userService) {
|
||||||
this.mailService = mailService;
|
this.mailService = mailService;
|
||||||
this.optionService = optionService;
|
this.optionService = optionService;
|
||||||
this.commentService = commentService;
|
this.postCommentService = postCommentService;
|
||||||
this.postService = postService;
|
this.postService = postService;
|
||||||
this.userService = userService;
|
this.userService = userService;
|
||||||
}
|
}
|
||||||
|
@ -60,10 +60,10 @@ public class CommentEventListener {
|
||||||
|
|
||||||
User user = userService.getCurrentUser().orElseThrow(() -> new ServiceException("Can not find blog owner"));
|
User user = userService.getCurrentUser().orElseThrow(() -> new ServiceException("Can not find blog owner"));
|
||||||
|
|
||||||
// Get comment id
|
// Get postComment id
|
||||||
Comment comment = commentService.getById(newEvent.getCommentId());
|
PostComment postComment = postCommentService.getById(newEvent.getCommentId());
|
||||||
|
|
||||||
Post post = postService.getById(comment.getPostId());
|
Post post = postService.getById(postComment.getPostId());
|
||||||
|
|
||||||
Map<String, Object> data = new HashMap<>();
|
Map<String, Object> data = new HashMap<>();
|
||||||
|
|
||||||
|
@ -72,8 +72,8 @@ public class CommentEventListener {
|
||||||
.append(post.getUrl());
|
.append(post.getUrl());
|
||||||
data.put("url", url.toString());
|
data.put("url", url.toString());
|
||||||
data.put("page", post.getTitle());
|
data.put("page", post.getTitle());
|
||||||
data.put("author", comment.getAuthor());
|
data.put("author", postComment.getAuthor());
|
||||||
data.put("content",comment.getContent());
|
data.put("content", postComment.getContent());
|
||||||
mailService.sendTemplateMail(user.getEmail(), "您的博客有新的评论", data, "common/mail_template/mail_notice.ftl");
|
mailService.sendTemplateMail(user.getEmail(), "您的博客有新的评论", data, "common/mail_template/mail_notice.ftl");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,8 +87,8 @@ public class CommentEventListener {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get comment id
|
// Get postComment id
|
||||||
Comment comment = commentService.getById(passEvent.getCommentId());
|
PostComment postComment = postCommentService.getById(passEvent.getCommentId());
|
||||||
|
|
||||||
// TODO Complete mail sending
|
// TODO Complete mail sending
|
||||||
}
|
}
|
||||||
|
@ -103,8 +103,8 @@ public class CommentEventListener {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get comment id
|
// Get postComment id
|
||||||
Comment comment = commentService.getById(replyEvent.getCommentId());
|
PostComment postComment = postCommentService.getById(replyEvent.getCommentId());
|
||||||
|
|
||||||
// TODO Complete mail sending
|
// TODO Complete mail sending
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ package run.halo.app.event.comment;
|
||||||
import org.springframework.lang.NonNull;
|
import org.springframework.lang.NonNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Comment new event.
|
* PostComment new event.
|
||||||
*
|
*
|
||||||
* @author johnniang
|
* @author johnniang
|
||||||
* @date 19-4-23
|
* @date 19-4-23
|
||||||
|
|
|
@ -3,7 +3,7 @@ package run.halo.app.event.comment;
|
||||||
import org.springframework.lang.NonNull;
|
import org.springframework.lang.NonNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Comment pass event.
|
* PostComment pass event.
|
||||||
*
|
*
|
||||||
* @author johnniang
|
* @author johnniang
|
||||||
* @date 19-4-23
|
* @date 19-4-23
|
||||||
|
|
|
@ -3,7 +3,7 @@ package run.halo.app.event.comment;
|
||||||
import org.springframework.lang.NonNull;
|
import org.springframework.lang.NonNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Comment reply event.
|
* PostComment reply event.
|
||||||
*
|
*
|
||||||
* @author johnniang
|
* @author johnniang
|
||||||
* @date 19-4-23
|
* @date 19-4-23
|
||||||
|
|
|
@ -4,12 +4,12 @@ import javax.persistence.DiscriminatorValue;
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Comment entity.
|
* PostComment entity.
|
||||||
*
|
*
|
||||||
* @author johnniang
|
* @author johnniang
|
||||||
*/
|
*/
|
||||||
@Entity(name = "Comment")
|
@Entity(name = "PostComment")
|
||||||
@DiscriminatorValue("0")
|
@DiscriminatorValue("0")
|
||||||
public class Comment extends BaseComment {
|
public class PostComment extends BaseComment {
|
||||||
|
|
||||||
}
|
}
|
|
@ -5,7 +5,7 @@ import run.halo.app.model.enums.CommentStatus;
|
||||||
import javax.persistence.Converter;
|
import javax.persistence.Converter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Comment status converter.
|
* PostComment status converter.
|
||||||
*
|
*
|
||||||
* @author johnniang
|
* @author johnniang
|
||||||
* @date 3/27/19
|
* @date 3/27/19
|
||||||
|
|
|
@ -4,7 +4,7 @@ import freemarker.core.Environment;
|
||||||
import freemarker.template.*;
|
import freemarker.template.*;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import run.halo.app.model.support.HaloConst;
|
import run.halo.app.model.support.HaloConst;
|
||||||
import run.halo.app.service.CommentService;
|
import run.halo.app.service.PostCommentService;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -18,10 +18,10 @@ import java.util.Map;
|
||||||
@Component
|
@Component
|
||||||
public class CommentTagDirective implements TemplateDirectiveModel {
|
public class CommentTagDirective implements TemplateDirectiveModel {
|
||||||
|
|
||||||
private final CommentService commentService;
|
private final PostCommentService postCommentService;
|
||||||
|
|
||||||
public CommentTagDirective(CommentService commentService) {
|
public CommentTagDirective(PostCommentService postCommentService) {
|
||||||
this.commentService = commentService;
|
this.postCommentService = postCommentService;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -33,10 +33,10 @@ public class CommentTagDirective implements TemplateDirectiveModel {
|
||||||
int top = Integer.parseInt(params.get("top").toString());
|
int top = Integer.parseInt(params.get("top").toString());
|
||||||
switch (method) {
|
switch (method) {
|
||||||
case "latest":
|
case "latest":
|
||||||
env.setVariable("categories", builder.build().wrap(commentService.pageLatest(top)));
|
env.setVariable("categories", builder.build().wrap(postCommentService.pageLatest(top)));
|
||||||
break;
|
break;
|
||||||
case "count":
|
case "count":
|
||||||
env.setVariable("count", builder.build().wrap(commentService.count()));
|
env.setVariable("count", builder.build().wrap(postCommentService.count()));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -19,26 +19,26 @@ import java.lang.reflect.ParameterizedType;
|
||||||
@Data
|
@Data
|
||||||
public abstract class BaseCommentParam<COMMENT> implements InputConverter<COMMENT> {
|
public abstract class BaseCommentParam<COMMENT> implements InputConverter<COMMENT> {
|
||||||
|
|
||||||
@NotBlank(message = "Comment author name must not be blank")
|
@NotBlank(message = "PostComment author name must not be blank")
|
||||||
@Size(max = 50, message = "Length of comment author name must not be more than {max}")
|
@Size(max = 50, message = "Length of comment author name must not be more than {max}")
|
||||||
private String author;
|
private String author;
|
||||||
|
|
||||||
@NotBlank(message = "Comment email must not be blank")
|
@NotBlank(message = "PostComment email must not be blank")
|
||||||
@Email(message = "Comment email's format is incorrect")
|
@Email(message = "PostComment email's format is incorrect")
|
||||||
@Size(max = 255, message = "Length of comment email must not be more than {max}")
|
@Size(max = 255, message = "Length of comment email must not be more than {max}")
|
||||||
private String email;
|
private String email;
|
||||||
|
|
||||||
@Size(max = 127, message = "Length of comment author url must not be more than {max}")
|
@Size(max = 127, message = "Length of comment author url must not be more than {max}")
|
||||||
private String authorUrl;
|
private String authorUrl;
|
||||||
|
|
||||||
@NotBlank(message = "Comment content must not be blank")
|
@NotBlank(message = "PostComment content must not be blank")
|
||||||
@Size(max = 1023, message = "Length of comment content must not be more than {max}")
|
@Size(max = 1023, message = "Length of comment content must not be more than {max}")
|
||||||
private String content;
|
private String content;
|
||||||
|
|
||||||
@Min(value = 1, message = "Post id must not be less than {value}")
|
@Min(value = 1, message = "Post id must not be less than {value}")
|
||||||
private Integer postId;
|
private Integer postId;
|
||||||
|
|
||||||
@Min(value = 0, message = "Comment parent id must not be less than {value}")
|
@Min(value = 0, message = "PostComment parent id must not be less than {value}")
|
||||||
private Long parentId = 0L;
|
private Long parentId = 0L;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -3,10 +3,10 @@ package run.halo.app.model.params;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
import lombok.ToString;
|
import lombok.ToString;
|
||||||
import run.halo.app.model.entity.Comment;
|
import run.halo.app.model.entity.PostComment;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Comment param.
|
* PostComment param.
|
||||||
*
|
*
|
||||||
* @author johnniang
|
* @author johnniang
|
||||||
* @date 3/22/19
|
* @date 3/22/19
|
||||||
|
@ -14,6 +14,6 @@ import run.halo.app.model.entity.Comment;
|
||||||
@Data
|
@Data
|
||||||
@ToString(callSuper = true)
|
@ToString(callSuper = true)
|
||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode(callSuper = true)
|
||||||
public class CommentParam extends BaseCommentParam<Comment> {
|
public class CommentParam extends BaseCommentParam<PostComment> {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Comment count projection
|
* PostComment count projection
|
||||||
*
|
*
|
||||||
* @author johnniang
|
* @author johnniang
|
||||||
* @date 3/22/19
|
* @date 3/22/19
|
||||||
|
|
|
@ -7,7 +7,7 @@ import org.springframework.data.domain.Pageable;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Comment page implementation.
|
* PostComment page implementation.
|
||||||
*
|
*
|
||||||
* @author johnniang
|
* @author johnniang
|
||||||
* @date 3/25/19
|
* @date 3/25/19
|
||||||
|
|
|
@ -7,14 +7,14 @@ import run.halo.app.model.dto.BaseCommentDTO;
|
||||||
import run.halo.app.model.dto.post.PostMinimalDTO;
|
import run.halo.app.model.dto.post.PostMinimalDTO;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Comment list with post vo.
|
* PostComment list with post vo.
|
||||||
*
|
*
|
||||||
* @author johnniang
|
* @author johnniang
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
@ToString
|
@ToString
|
||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode(callSuper = true)
|
||||||
public class CommentWithPostVO extends BaseCommentDTO {
|
public class PostCommentWithPostVO extends BaseCommentDTO {
|
||||||
|
|
||||||
private PostMinimalDTO post;
|
private PostMinimalDTO post;
|
||||||
}
|
}
|
|
@ -2,21 +2,21 @@ package run.halo.app.repository;
|
||||||
|
|
||||||
import org.springframework.data.jpa.repository.Query;
|
import org.springframework.data.jpa.repository.Query;
|
||||||
import org.springframework.lang.NonNull;
|
import org.springframework.lang.NonNull;
|
||||||
import run.halo.app.model.entity.Comment;
|
import run.halo.app.model.entity.PostComment;
|
||||||
import run.halo.app.model.projection.CommentCountProjection;
|
import run.halo.app.model.projection.CommentCountProjection;
|
||||||
import run.halo.app.repository.base.BaseCommentRepository;
|
import run.halo.app.repository.base.BaseCommentRepository;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Comment repository.
|
* PostComment repository.
|
||||||
*
|
*
|
||||||
* @author johnniang
|
* @author johnniang
|
||||||
* @date 3/21/19
|
* @date 3/21/19
|
||||||
*/
|
*/
|
||||||
public interface CommentRepository extends BaseCommentRepository<Comment> {
|
public interface PostCommentRepository extends BaseCommentRepository<PostComment> {
|
||||||
|
|
||||||
@Query("select new run.halo.app.model.projection.CommentCountProjection(count(comment.id), comment.postId) from BaseComment comment where comment.postId in ?1 group by comment.postId")
|
@Query("select new run.halo.app.model.projection.CommentCountProjection(count(comment.id), comment.postId) from PostComment comment where comment.postId in ?1 group by comment.postId")
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
List<CommentCountProjection> countByPostIds(@NonNull Iterable<Integer> postIds);
|
List<CommentCountProjection> countByPostIds(@NonNull Iterable<Integer> postIds);
|
|
@ -3,6 +3,7 @@ package run.halo.app.repository.base;
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||||
|
import org.springframework.data.jpa.repository.Query;
|
||||||
import org.springframework.data.repository.NoRepositoryBean;
|
import org.springframework.data.repository.NoRepositoryBean;
|
||||||
import org.springframework.lang.NonNull;
|
import org.springframework.lang.NonNull;
|
||||||
import org.springframework.lang.Nullable;
|
import org.springframework.lang.Nullable;
|
||||||
|
|
|
@ -3,19 +3,18 @@ package run.halo.app.service;
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.lang.NonNull;
|
import org.springframework.lang.NonNull;
|
||||||
import org.springframework.lang.Nullable;
|
import org.springframework.lang.Nullable;
|
||||||
import run.halo.app.model.entity.Comment;
|
import run.halo.app.model.entity.PostComment;
|
||||||
import run.halo.app.model.params.CommentParam;
|
import run.halo.app.model.vo.PostCommentWithPostVO;
|
||||||
import run.halo.app.model.vo.CommentWithPostVO;
|
|
||||||
import run.halo.app.service.base.BaseCommentService;
|
import run.halo.app.service.base.BaseCommentService;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Comment service.
|
* PostComment service.
|
||||||
*
|
*
|
||||||
* @author johnniang
|
* @author johnniang
|
||||||
*/
|
*/
|
||||||
public interface CommentService extends BaseCommentService<Comment> {
|
public interface PostCommentService extends BaseCommentService<PostComment> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts to with post vo.
|
* Converts to with post vo.
|
||||||
|
@ -24,14 +23,14 @@ public interface CommentService extends BaseCommentService<Comment> {
|
||||||
* @return a page of comment with post vo
|
* @return a page of comment with post vo
|
||||||
*/
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
Page<CommentWithPostVO> convertToWithPostVo(@NonNull Page<Comment> commentPage);
|
Page<PostCommentWithPostVO> convertToWithPostVo(@NonNull Page<PostComment> commentPage);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts to with post vo
|
* Converts to with post vo
|
||||||
*
|
*
|
||||||
* @param comments comment list
|
* @param postComments comment list
|
||||||
* @return a list of comment with post vo
|
* @return a list of comment with post vo
|
||||||
*/
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
List<CommentWithPostVO> convertToWithPostVo(@Nullable List<Comment> comments);
|
List<PostCommentWithPostVO> convertToWithPostVo(@Nullable List<PostComment> postComments);
|
||||||
}
|
}
|
|
@ -9,12 +9,12 @@ import org.springframework.util.Assert;
|
||||||
import org.springframework.util.CollectionUtils;
|
import org.springframework.util.CollectionUtils;
|
||||||
import run.halo.app.exception.NotFoundException;
|
import run.halo.app.exception.NotFoundException;
|
||||||
import run.halo.app.model.dto.post.PostMinimalDTO;
|
import run.halo.app.model.dto.post.PostMinimalDTO;
|
||||||
import run.halo.app.model.entity.Comment;
|
import run.halo.app.model.entity.PostComment;
|
||||||
import run.halo.app.model.entity.Post;
|
import run.halo.app.model.entity.Post;
|
||||||
import run.halo.app.model.vo.CommentWithPostVO;
|
import run.halo.app.model.vo.PostCommentWithPostVO;
|
||||||
import run.halo.app.repository.CommentRepository;
|
import run.halo.app.repository.PostCommentRepository;
|
||||||
import run.halo.app.repository.PostRepository;
|
import run.halo.app.repository.PostRepository;
|
||||||
import run.halo.app.service.CommentService;
|
import run.halo.app.service.PostCommentService;
|
||||||
import run.halo.app.service.OptionService;
|
import run.halo.app.service.OptionService;
|
||||||
import run.halo.app.utils.ServiceUtils;
|
import run.halo.app.utils.ServiceUtils;
|
||||||
|
|
||||||
|
@ -25,56 +25,56 @@ import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* CommentService implementation class
|
* PostCommentService implementation class
|
||||||
*
|
*
|
||||||
* @author : RYAN0UP
|
* @author : RYAN0UP
|
||||||
* @date : 2019-03-14
|
* @date : 2019-03-14
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Service
|
@Service
|
||||||
public class CommentServiceImpl extends BaseCommentServiceImpl<Comment> implements CommentService {
|
public class PostCommentServiceImpl extends BaseCommentServiceImpl<PostComment> implements PostCommentService {
|
||||||
|
|
||||||
private final CommentRepository commentRepository;
|
private final PostCommentRepository postCommentRepository;
|
||||||
|
|
||||||
private final PostRepository postRepository;
|
private final PostRepository postRepository;
|
||||||
|
|
||||||
public CommentServiceImpl(CommentRepository commentRepository,
|
public PostCommentServiceImpl(PostCommentRepository postCommentRepository,
|
||||||
PostRepository postRepository,
|
PostRepository postRepository,
|
||||||
OptionService optionService,
|
OptionService optionService,
|
||||||
ApplicationEventPublisher eventPublisher) {
|
ApplicationEventPublisher eventPublisher) {
|
||||||
super(commentRepository, optionService, eventPublisher);
|
super(postCommentRepository, optionService, eventPublisher);
|
||||||
this.commentRepository = commentRepository;
|
this.postCommentRepository = postCommentRepository;
|
||||||
this.postRepository = postRepository;
|
this.postRepository = postRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Page<CommentWithPostVO> convertToWithPostVo(Page<Comment> commentPage) {
|
public Page<PostCommentWithPostVO> convertToWithPostVo(Page<PostComment> commentPage) {
|
||||||
Assert.notNull(commentPage, "Comment page must not be null");
|
Assert.notNull(commentPage, "PostComment page must not be null");
|
||||||
|
|
||||||
return new PageImpl<>(convertToWithPostVo(commentPage.getContent()), commentPage.getPageable(), commentPage.getTotalElements());
|
return new PageImpl<>(convertToWithPostVo(commentPage.getContent()), commentPage.getPageable(), commentPage.getTotalElements());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<CommentWithPostVO> convertToWithPostVo(List<Comment> comments) {
|
public List<PostCommentWithPostVO> convertToWithPostVo(List<PostComment> postComments) {
|
||||||
if (CollectionUtils.isEmpty(comments)) {
|
if (CollectionUtils.isEmpty(postComments)) {
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fetch goods ids
|
// Fetch goods ids
|
||||||
Set<Integer> postIds = ServiceUtils.fetchProperty(comments, Comment::getPostId);
|
Set<Integer> postIds = ServiceUtils.fetchProperty(postComments, PostComment::getPostId);
|
||||||
|
|
||||||
// Get all posts
|
// Get all posts
|
||||||
Map<Integer, Post> postMap = ServiceUtils.convertToMap(postRepository.findAllById(postIds), Post::getId);
|
Map<Integer, Post> postMap = ServiceUtils.convertToMap(postRepository.findAllById(postIds), Post::getId);
|
||||||
|
|
||||||
return comments.stream().map(comment -> {
|
return postComments.stream().map(comment -> {
|
||||||
// Convert to vo
|
// Convert to vo
|
||||||
CommentWithPostVO commentWithPostVO = new CommentWithPostVO().convertFrom(comment);
|
PostCommentWithPostVO postCommentWithPostVO = new PostCommentWithPostVO().convertFrom(comment);
|
||||||
|
|
||||||
// Get post and set to the vo
|
// Get post and set to the vo
|
||||||
commentWithPostVO.setPost(new PostMinimalDTO().convertFrom(postMap.get(comment.getPostId())));
|
postCommentWithPostVO.setPost(new PostMinimalDTO().convertFrom(postMap.get(comment.getPostId())));
|
||||||
|
|
||||||
return commentWithPostVO;
|
return postCommentWithPostVO;
|
||||||
}).collect(Collectors.toList());
|
}).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,7 +60,7 @@ public class PostServiceImpl extends BasePostServiceImpl<Post> implements PostSe
|
||||||
|
|
||||||
private final PostCategoryService postCategoryService;
|
private final PostCategoryService postCategoryService;
|
||||||
|
|
||||||
private final CommentService commentService;
|
private final PostCommentService postCommentService;
|
||||||
|
|
||||||
private final ApplicationEventPublisher eventPublisher;
|
private final ApplicationEventPublisher eventPublisher;
|
||||||
|
|
||||||
|
@ -69,7 +69,7 @@ public class PostServiceImpl extends BasePostServiceImpl<Post> implements PostSe
|
||||||
CategoryService categoryService,
|
CategoryService categoryService,
|
||||||
PostTagService postTagService,
|
PostTagService postTagService,
|
||||||
PostCategoryService postCategoryService,
|
PostCategoryService postCategoryService,
|
||||||
CommentService commentService,
|
PostCommentService postCommentService,
|
||||||
ApplicationEventPublisher eventPublisher) {
|
ApplicationEventPublisher eventPublisher) {
|
||||||
super(postRepository);
|
super(postRepository);
|
||||||
this.postRepository = postRepository;
|
this.postRepository = postRepository;
|
||||||
|
@ -77,7 +77,7 @@ public class PostServiceImpl extends BasePostServiceImpl<Post> implements PostSe
|
||||||
this.categoryService = categoryService;
|
this.categoryService = categoryService;
|
||||||
this.postTagService = postTagService;
|
this.postTagService = postTagService;
|
||||||
this.postCategoryService = postCategoryService;
|
this.postCategoryService = postCategoryService;
|
||||||
this.commentService = commentService;
|
this.postCommentService = postCommentService;
|
||||||
this.eventPublisher = eventPublisher;
|
this.eventPublisher = eventPublisher;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -369,7 +369,7 @@ public class PostServiceImpl extends BasePostServiceImpl<Post> implements PostSe
|
||||||
Map<Integer, List<Category>> categoryListMap = postCategoryService.listCategoryListMap(postIds);
|
Map<Integer, List<Category>> categoryListMap = postCategoryService.listCategoryListMap(postIds);
|
||||||
|
|
||||||
// Get comment count
|
// Get comment count
|
||||||
Map<Integer, Long> commentCountMap = commentService.countByPostIds(postIds);
|
Map<Integer, Long> commentCountMap = postCommentService.countByPostIds(postIds);
|
||||||
|
|
||||||
|
|
||||||
return postPage.map(post -> {
|
return postPage.map(post -> {
|
||||||
|
|
Loading…
Reference in New Issue