From c3985cf9c53d7da4106f6ba4199b940b976c55b6 Mon Sep 17 00:00:00 2001 From: johnniang Date: Thu, 25 Apr 2019 20:34:02 +0800 Subject: [PATCH] Rename comment to post comment --- .../controller/admin/api/AdminController.java | 8 +- .../admin/api/CommentController.java | 82 ------------------- .../admin/api/PostCommentController.java | 75 +++++++++++++++++ .../controller/admin/api/PostController.java | 10 +-- .../content/ContentArchiveController.java | 8 +- .../content/ContentSheetController.java | 8 +- .../content/api/CommentController.java | 10 +-- .../content/api/PostController.java | 12 +-- .../controller/core/InstallController.java | 12 +-- .../app/event/comment/CommentBaseEvent.java | 6 +- .../event/comment/CommentEventListener.java | 28 +++---- .../app/event/comment/CommentNewEvent.java | 2 +- .../app/event/comment/CommentPassEvent.java | 2 +- .../app/event/comment/CommentReplyEvent.java | 2 +- .../entity/{Comment.java => PostComment.java} | 6 +- .../converter/CommentStatusConverter.java | 2 +- .../freemarker/tag/CommentTagDirective.java | 12 +-- .../app/model/params/BaseCommentParam.java | 10 +-- .../halo/app/model/params/CommentParam.java | 6 +- .../projection/CommentCountProjection.java | 2 +- .../halo/app/model/support/CommentPage.java | 2 +- ...PostVO.java => PostCommentWithPostVO.java} | 4 +- ...sitory.java => PostCommentRepository.java} | 8 +- .../base/BaseCommentRepository.java | 1 + ...ntService.java => PostCommentService.java} | 15 ++-- ...eImpl.java => PostCommentServiceImpl.java} | 44 +++++----- .../app/service/impl/PostServiceImpl.java | 8 +- 27 files changed, 185 insertions(+), 200 deletions(-) delete mode 100644 src/main/java/run/halo/app/controller/admin/api/CommentController.java create mode 100644 src/main/java/run/halo/app/controller/admin/api/PostCommentController.java rename src/main/java/run/halo/app/model/entity/{Comment.java => PostComment.java} (63%) rename src/main/java/run/halo/app/model/vo/{CommentWithPostVO.java => PostCommentWithPostVO.java} (77%) rename src/main/java/run/halo/app/repository/{CommentRepository.java => PostCommentRepository.java} (71%) rename src/main/java/run/halo/app/service/{CommentService.java => PostCommentService.java} (56%) rename src/main/java/run/halo/app/service/impl/{CommentServiceImpl.java => PostCommentServiceImpl.java} (51%) diff --git a/src/main/java/run/halo/app/controller/admin/api/AdminController.java b/src/main/java/run/halo/app/controller/admin/api/AdminController.java index d0f97c64..ed6ddb45 100644 --- a/src/main/java/run/halo/app/controller/admin/api/AdminController.java +++ b/src/main/java/run/halo/app/controller/admin/api/AdminController.java @@ -32,7 +32,7 @@ public class AdminController { private final AttachmentService attachmentService; - private final CommentService commentService; + private final PostCommentService postCommentService; private final OptionService optionService; @@ -42,13 +42,13 @@ public class AdminController { public AdminController(PostService postService, AttachmentService attachmentService, - CommentService commentService, + PostCommentService postCommentService, OptionService optionService, UserService userService, LinkService linkService) { this.postService = postService; this.attachmentService = attachmentService; - this.commentService = commentService; + this.postCommentService = postCommentService; this.optionService = optionService; this.userService = userService; this.linkService = linkService; @@ -65,7 +65,7 @@ public class AdminController { CountDTO countDTO = new CountDTO(); countDTO.setPostCount(postService.countByStatus(PostStatus.PUBLISHED)); countDTO.setAttachmentCount(attachmentService.count()); - countDTO.setCommentCount(commentService.count()); + countDTO.setCommentCount(postCommentService.count()); long currentTimeMillis = System.currentTimeMillis(); diff --git a/src/main/java/run/halo/app/controller/admin/api/CommentController.java b/src/main/java/run/halo/app/controller/admin/api/CommentController.java deleted file mode 100644 index c15084c8..00000000 --- a/src/main/java/run/halo/app/controller/admin/api/CommentController.java +++ /dev/null @@ -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 pageBy(@PageableDefault(sort = "updateTime", direction = DESC) Pageable pageable, - CommentQuery commentQuery) { - Page commentPage = commentService.pageBy(commentQuery, pageable); - return commentService.convertToWithPostVo(commentPage); - } - - @GetMapping("latest") - @ApiOperation("Pages latest comments") - public List pageLatest(@RequestParam(name = "top", defaultValue = "10") int top) { - List content = commentService.pageLatest(top).getContent(); - return commentService.convertToWithPostVo(content); - } - - @GetMapping("status/{status}") - public Page pageBy(@PageableDefault(sort = "updateTime", direction = DESC) Pageable pageable, - @PathVariable("status") CommentStatus status) { - Page 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); - } -} diff --git a/src/main/java/run/halo/app/controller/admin/api/PostCommentController.java b/src/main/java/run/halo/app/controller/admin/api/PostCommentController.java new file mode 100644 index 00000000..3b8face6 --- /dev/null +++ b/src/main/java/run/halo/app/controller/admin/api/PostCommentController.java @@ -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 pageBy(@PageableDefault(sort = "updateTime", direction = DESC) Pageable pageable, + CommentQuery commentQuery) { + Page commentPage = postCommentService.pageBy(commentQuery, pageable); + return postCommentService.convertToWithPostVo(commentPage); + } + + @GetMapping("latest") + @ApiOperation("Pages latest comments") + public List pageLatest(@RequestParam(name = "top", defaultValue = "10") int top) { + List 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); + } +} diff --git a/src/main/java/run/halo/app/controller/admin/api/PostController.java b/src/main/java/run/halo/app/controller/admin/api/PostController.java index c3762d4c..ee41fc73 100644 --- a/src/main/java/run/halo/app/controller/admin/api/PostController.java +++ b/src/main/java/run/halo/app/controller/admin/api/PostController.java @@ -36,20 +36,12 @@ public class PostController { private final PostTagService postTagService; - private final CommentService commentService; - - private final OptionService optionService; - public PostController(PostService postService, PostCategoryService postCategoryService, - PostTagService postTagService, - CommentService commentService, - OptionService optionService) { + PostTagService postTagService) { this.postService = postService; this.postCategoryService = postCategoryService; this.postTagService = postTagService; - this.commentService = commentService; - this.optionService = optionService; } @GetMapping diff --git a/src/main/java/run/halo/app/controller/content/ContentArchiveController.java b/src/main/java/run/halo/app/controller/content/ContentArchiveController.java index 87a9c1af..e286aaed 100644 --- a/src/main/java/run/halo/app/controller/content/ContentArchiveController.java +++ b/src/main/java/run/halo/app/controller/content/ContentArchiveController.java @@ -38,7 +38,7 @@ public class ContentArchiveController { private final PostService postService; - private final CommentService commentService; + private final PostCommentService postCommentService; private final ThemeService themeService; @@ -49,13 +49,13 @@ public class ContentArchiveController { private final OptionService optionService; public ContentArchiveController(PostService postService, - CommentService commentService, + PostCommentService postCommentService, ThemeService themeService, PostCategoryService postCategoryService, PostTagService postTagService, OptionService optionService) { this.postService = postService; - this.commentService = commentService; + this.postCommentService = postCommentService; this.themeService = themeService; this.postCategoryService = postCategoryService; this.postTagService = postTagService; @@ -116,7 +116,7 @@ public class ContentArchiveController { List categories = postCategoryService.listCategoryBy(post.getId()); List tags = postTagService.listTagsBy(post.getId()); - Page comments = commentService.pageVosBy(post.getId(), PageRequest.of(cp, optionService.getCommentPageSize(), sort)); + Page comments = postCommentService.pageVosBy(post.getId(), PageRequest.of(cp, optionService.getCommentPageSize(), sort)); final int[] pageRainbow = PageUtil.rainbow(cp, comments.getTotalPages(), 3); model.addAttribute("is_post", true); diff --git a/src/main/java/run/halo/app/controller/content/ContentSheetController.java b/src/main/java/run/halo/app/controller/content/ContentSheetController.java index d6ad6827..d67cf116 100644 --- a/src/main/java/run/halo/app/controller/content/ContentSheetController.java +++ b/src/main/java/run/halo/app/controller/content/ContentSheetController.java @@ -8,7 +8,7 @@ import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestParam; import run.halo.app.model.entity.Sheet; 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.ThemeService; @@ -22,15 +22,15 @@ public class ContentSheetController { private final SheetService sheetService; - private final CommentService commentService; + private final PostCommentService postCommentService; private final ThemeService themeService; public ContentSheetController(SheetService sheetService, - CommentService commentService, + PostCommentService postCommentService, ThemeService themeService) { this.sheetService = sheetService; - this.commentService = commentService; + this.postCommentService = postCommentService; this.themeService = themeService; } diff --git a/src/main/java/run/halo/app/controller/content/api/CommentController.java b/src/main/java/run/halo/app/controller/content/api/CommentController.java index 61525ce1..f47cf8b3 100644 --- a/src/main/java/run/halo/app/controller/content/api/CommentController.java +++ b/src/main/java/run/halo/app/controller/content/api/CommentController.java @@ -7,7 +7,7 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import run.halo.app.model.dto.BaseCommentDTO; import run.halo.app.model.params.CommentParam; -import run.halo.app.service.CommentService; +import run.halo.app.service.PostCommentService; /** * Portal comment controller. @@ -19,15 +19,15 @@ import run.halo.app.service.CommentService; @RequestMapping("/api/comments") public class CommentController { - private final CommentService commentService; + private final PostCommentService postCommentService; - public CommentController(CommentService commentService) { - this.commentService = commentService; + public CommentController(PostCommentService postCommentService) { + this.postCommentService = postCommentService; } @PostMapping @ApiOperation("Comments a post") public BaseCommentDTO comment(@RequestBody CommentParam commentParam) { - return commentService.convertTo(commentService.createBy(commentParam)); + return postCommentService.convertTo(postCommentService.createBy(commentParam)); } } diff --git a/src/main/java/run/halo/app/controller/content/api/PostController.java b/src/main/java/run/halo/app/controller/content/api/PostController.java index 3f8f4031..b6650cb6 100644 --- a/src/main/java/run/halo/app/controller/content/api/PostController.java +++ b/src/main/java/run/halo/app/controller/content/api/PostController.java @@ -13,7 +13,7 @@ import run.halo.app.model.dto.post.PostSimpleDTO; import run.halo.app.model.enums.PostStatus; import run.halo.app.model.vo.BaseCommentVO; 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.PostService; @@ -31,15 +31,15 @@ public class PostController { private final PostService postService; - private final CommentService commentService; + private final PostCommentService postCommentService; private final OptionService optionService; public PostController(PostService postService, - CommentService commentService, + PostCommentService postCommentService, OptionService optionService) { this.postService = postService; - this.commentService = commentService; + this.postCommentService = postCommentService; this.optionService = optionService; } @@ -74,7 +74,7 @@ public class PostController { public Page listCommentsTree(@PathVariable("postId") Integer postId, @RequestParam(name = "page", required = false, defaultValue = "0") int page, @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") @@ -82,7 +82,7 @@ public class PostController { public Page listComments(@PathVariable("postId") Integer postId, @RequestParam(name = "page", required = false, defaultValue = "0") int page, @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") diff --git a/src/main/java/run/halo/app/controller/core/InstallController.java b/src/main/java/run/halo/app/controller/core/InstallController.java index 70f09f36..cf3b5c38 100644 --- a/src/main/java/run/halo/app/controller/core/InstallController.java +++ b/src/main/java/run/halo/app/controller/core/InstallController.java @@ -43,7 +43,7 @@ public class InstallController { private final PostService postService; - private final CommentService commentService; + private final PostCommentService postCommentService; private final OptionService optionService; @@ -56,7 +56,7 @@ public class InstallController { public InstallController(UserService userService, CategoryService categoryService, PostService postService, - CommentService commentService, + PostCommentService postCommentService, OptionService optionService, MenuService menuService, Configuration configuration, @@ -64,7 +64,7 @@ public class InstallController { this.userService = userService; this.categoryService = categoryService; this.postService = postService; - this.commentService = commentService; + this.postCommentService = postCommentService; this.optionService = optionService; this.menuService = menuService; this.configuration = configuration; @@ -115,8 +115,8 @@ public class InstallController { // Create default post Post post = createDefaultPost(category); - // Create default comment - Comment comment = createDefaultComment(); + // Create default postComment + PostComment postComment = createDefaultComment(); // Create default menu createDefaultMenu(); @@ -149,7 +149,7 @@ public class InstallController { } - private Comment createDefaultComment() { + private PostComment createDefaultComment() { // TODO Create default comment return null; } diff --git a/src/main/java/run/halo/app/event/comment/CommentBaseEvent.java b/src/main/java/run/halo/app/event/comment/CommentBaseEvent.java index bc9ba69d..a283fd99 100644 --- a/src/main/java/run/halo/app/event/comment/CommentBaseEvent.java +++ b/src/main/java/run/halo/app/event/comment/CommentBaseEvent.java @@ -5,7 +5,7 @@ import org.springframework.lang.NonNull; import org.springframework.util.Assert; /** - * Comment new event. + * PostComment new event. * * @author johnniang * @date 19-4-23 @@ -13,7 +13,7 @@ import org.springframework.util.Assert; public abstract class CommentBaseEvent extends ApplicationEvent { /** - * Comment id. + * PostComment id. */ private final Long commentId; @@ -26,7 +26,7 @@ public abstract class CommentBaseEvent extends ApplicationEvent { public CommentBaseEvent(Object source, @NonNull Long commentId) { super(source); - Assert.notNull(commentId, "Comment id must not be null"); + Assert.notNull(commentId, "PostComment id must not be null"); this.commentId = commentId; } diff --git a/src/main/java/run/halo/app/event/comment/CommentEventListener.java b/src/main/java/run/halo/app/event/comment/CommentEventListener.java index 554eb1df..017c4912 100644 --- a/src/main/java/run/halo/app/event/comment/CommentEventListener.java +++ b/src/main/java/run/halo/app/event/comment/CommentEventListener.java @@ -6,7 +6,7 @@ import org.springframework.context.event.EventListener; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Component; 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.User; import run.halo.app.model.properties.BlogProperties; @@ -17,7 +17,7 @@ import java.util.HashMap; import java.util.Map; /** - * Comment event listener. + * PostComment event listener. * * @author johnniang * @date 19-4-23 @@ -30,7 +30,7 @@ public class CommentEventListener { private final OptionService optionService; - private final CommentService commentService; + private final PostCommentService postCommentService; private final PostService postService; @@ -38,12 +38,12 @@ public class CommentEventListener { public CommentEventListener(MailService mailService, OptionService optionService, - CommentService commentService, + PostCommentService postCommentService, PostService postService, UserService userService) { this.mailService = mailService; this.optionService = optionService; - this.commentService = commentService; + this.postCommentService = postCommentService; this.postService = postService; this.userService = userService; } @@ -60,10 +60,10 @@ public class CommentEventListener { User user = userService.getCurrentUser().orElseThrow(() -> new ServiceException("Can not find blog owner")); - // Get comment id - Comment comment = commentService.getById(newEvent.getCommentId()); + // Get postComment id + PostComment postComment = postCommentService.getById(newEvent.getCommentId()); - Post post = postService.getById(comment.getPostId()); + Post post = postService.getById(postComment.getPostId()); Map data = new HashMap<>(); @@ -72,8 +72,8 @@ public class CommentEventListener { .append(post.getUrl()); data.put("url", url.toString()); data.put("page", post.getTitle()); - data.put("author", comment.getAuthor()); - data.put("content",comment.getContent()); + data.put("author", postComment.getAuthor()); + data.put("content", postComment.getContent()); mailService.sendTemplateMail(user.getEmail(), "您的博客有新的评论", data, "common/mail_template/mail_notice.ftl"); } @@ -87,8 +87,8 @@ public class CommentEventListener { return; } - // Get comment id - Comment comment = commentService.getById(passEvent.getCommentId()); + // Get postComment id + PostComment postComment = postCommentService.getById(passEvent.getCommentId()); // TODO Complete mail sending } @@ -103,8 +103,8 @@ public class CommentEventListener { return; } - // Get comment id - Comment comment = commentService.getById(replyEvent.getCommentId()); + // Get postComment id + PostComment postComment = postCommentService.getById(replyEvent.getCommentId()); // TODO Complete mail sending } diff --git a/src/main/java/run/halo/app/event/comment/CommentNewEvent.java b/src/main/java/run/halo/app/event/comment/CommentNewEvent.java index 2a2c3e81..c74f0042 100644 --- a/src/main/java/run/halo/app/event/comment/CommentNewEvent.java +++ b/src/main/java/run/halo/app/event/comment/CommentNewEvent.java @@ -3,7 +3,7 @@ package run.halo.app.event.comment; import org.springframework.lang.NonNull; /** - * Comment new event. + * PostComment new event. * * @author johnniang * @date 19-4-23 diff --git a/src/main/java/run/halo/app/event/comment/CommentPassEvent.java b/src/main/java/run/halo/app/event/comment/CommentPassEvent.java index 08153ecc..c2986527 100644 --- a/src/main/java/run/halo/app/event/comment/CommentPassEvent.java +++ b/src/main/java/run/halo/app/event/comment/CommentPassEvent.java @@ -3,7 +3,7 @@ package run.halo.app.event.comment; import org.springframework.lang.NonNull; /** - * Comment pass event. + * PostComment pass event. * * @author johnniang * @date 19-4-23 diff --git a/src/main/java/run/halo/app/event/comment/CommentReplyEvent.java b/src/main/java/run/halo/app/event/comment/CommentReplyEvent.java index c3707857..658cbbeb 100644 --- a/src/main/java/run/halo/app/event/comment/CommentReplyEvent.java +++ b/src/main/java/run/halo/app/event/comment/CommentReplyEvent.java @@ -3,7 +3,7 @@ package run.halo.app.event.comment; import org.springframework.lang.NonNull; /** - * Comment reply event. + * PostComment reply event. * * @author johnniang * @date 19-4-23 diff --git a/src/main/java/run/halo/app/model/entity/Comment.java b/src/main/java/run/halo/app/model/entity/PostComment.java similarity index 63% rename from src/main/java/run/halo/app/model/entity/Comment.java rename to src/main/java/run/halo/app/model/entity/PostComment.java index d9e4456e..1cd2c5ff 100644 --- a/src/main/java/run/halo/app/model/entity/Comment.java +++ b/src/main/java/run/halo/app/model/entity/PostComment.java @@ -4,12 +4,12 @@ import javax.persistence.DiscriminatorValue; import javax.persistence.Entity; /** - * Comment entity. + * PostComment entity. * * @author johnniang */ -@Entity(name = "Comment") +@Entity(name = "PostComment") @DiscriminatorValue("0") -public class Comment extends BaseComment { +public class PostComment extends BaseComment { } diff --git a/src/main/java/run/halo/app/model/enums/converter/CommentStatusConverter.java b/src/main/java/run/halo/app/model/enums/converter/CommentStatusConverter.java index fcbd3e8b..9ab9ff71 100644 --- a/src/main/java/run/halo/app/model/enums/converter/CommentStatusConverter.java +++ b/src/main/java/run/halo/app/model/enums/converter/CommentStatusConverter.java @@ -5,7 +5,7 @@ import run.halo.app.model.enums.CommentStatus; import javax.persistence.Converter; /** - * Comment status converter. + * PostComment status converter. * * @author johnniang * @date 3/27/19 diff --git a/src/main/java/run/halo/app/model/freemarker/tag/CommentTagDirective.java b/src/main/java/run/halo/app/model/freemarker/tag/CommentTagDirective.java index 21c46fb4..027c2caa 100644 --- a/src/main/java/run/halo/app/model/freemarker/tag/CommentTagDirective.java +++ b/src/main/java/run/halo/app/model/freemarker/tag/CommentTagDirective.java @@ -4,7 +4,7 @@ import freemarker.core.Environment; import freemarker.template.*; import org.springframework.stereotype.Component; 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.util.Map; @@ -18,10 +18,10 @@ import java.util.Map; @Component public class CommentTagDirective implements TemplateDirectiveModel { - private final CommentService commentService; + private final PostCommentService postCommentService; - public CommentTagDirective(CommentService commentService) { - this.commentService = commentService; + public CommentTagDirective(PostCommentService postCommentService) { + this.postCommentService = postCommentService; } @Override @@ -33,10 +33,10 @@ public class CommentTagDirective implements TemplateDirectiveModel { int top = Integer.parseInt(params.get("top").toString()); switch (method) { case "latest": - env.setVariable("categories", builder.build().wrap(commentService.pageLatest(top))); + env.setVariable("categories", builder.build().wrap(postCommentService.pageLatest(top))); break; case "count": - env.setVariable("count", builder.build().wrap(commentService.count())); + env.setVariable("count", builder.build().wrap(postCommentService.count())); break; default: break; diff --git a/src/main/java/run/halo/app/model/params/BaseCommentParam.java b/src/main/java/run/halo/app/model/params/BaseCommentParam.java index 58543e5e..e1f343b6 100644 --- a/src/main/java/run/halo/app/model/params/BaseCommentParam.java +++ b/src/main/java/run/halo/app/model/params/BaseCommentParam.java @@ -19,26 +19,26 @@ import java.lang.reflect.ParameterizedType; @Data public abstract class BaseCommentParam implements InputConverter { - @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}") private String author; - @NotBlank(message = "Comment email must not be blank") - @Email(message = "Comment email's format is incorrect") + @NotBlank(message = "PostComment email must not be blank") + @Email(message = "PostComment email's format is incorrect") @Size(max = 255, message = "Length of comment email must not be more than {max}") private String email; @Size(max = 127, message = "Length of comment author url must not be more than {max}") 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}") private String content; @Min(value = 1, message = "Post id must not be less than {value}") 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; @Override diff --git a/src/main/java/run/halo/app/model/params/CommentParam.java b/src/main/java/run/halo/app/model/params/CommentParam.java index 013180ea..a1c442b7 100644 --- a/src/main/java/run/halo/app/model/params/CommentParam.java +++ b/src/main/java/run/halo/app/model/params/CommentParam.java @@ -3,10 +3,10 @@ package run.halo.app.model.params; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.ToString; -import run.halo.app.model.entity.Comment; +import run.halo.app.model.entity.PostComment; /** - * Comment param. + * PostComment param. * * @author johnniang * @date 3/22/19 @@ -14,6 +14,6 @@ import run.halo.app.model.entity.Comment; @Data @ToString(callSuper = true) @EqualsAndHashCode(callSuper = true) -public class CommentParam extends BaseCommentParam { +public class CommentParam extends BaseCommentParam { } diff --git a/src/main/java/run/halo/app/model/projection/CommentCountProjection.java b/src/main/java/run/halo/app/model/projection/CommentCountProjection.java index 83356d00..5e5bae30 100644 --- a/src/main/java/run/halo/app/model/projection/CommentCountProjection.java +++ b/src/main/java/run/halo/app/model/projection/CommentCountProjection.java @@ -5,7 +5,7 @@ import lombok.Data; import lombok.NoArgsConstructor; /** - * Comment count projection + * PostComment count projection * * @author johnniang * @date 3/22/19 diff --git a/src/main/java/run/halo/app/model/support/CommentPage.java b/src/main/java/run/halo/app/model/support/CommentPage.java index ea1609d2..afae0b95 100644 --- a/src/main/java/run/halo/app/model/support/CommentPage.java +++ b/src/main/java/run/halo/app/model/support/CommentPage.java @@ -7,7 +7,7 @@ import org.springframework.data.domain.Pageable; import java.util.List; /** - * Comment page implementation. + * PostComment page implementation. * * @author johnniang * @date 3/25/19 diff --git a/src/main/java/run/halo/app/model/vo/CommentWithPostVO.java b/src/main/java/run/halo/app/model/vo/PostCommentWithPostVO.java similarity index 77% rename from src/main/java/run/halo/app/model/vo/CommentWithPostVO.java rename to src/main/java/run/halo/app/model/vo/PostCommentWithPostVO.java index b0723e34..19355393 100644 --- a/src/main/java/run/halo/app/model/vo/CommentWithPostVO.java +++ b/src/main/java/run/halo/app/model/vo/PostCommentWithPostVO.java @@ -7,14 +7,14 @@ import run.halo.app.model.dto.BaseCommentDTO; import run.halo.app.model.dto.post.PostMinimalDTO; /** - * Comment list with post vo. + * PostComment list with post vo. * * @author johnniang */ @Data @ToString @EqualsAndHashCode(callSuper = true) -public class CommentWithPostVO extends BaseCommentDTO { +public class PostCommentWithPostVO extends BaseCommentDTO { private PostMinimalDTO post; } diff --git a/src/main/java/run/halo/app/repository/CommentRepository.java b/src/main/java/run/halo/app/repository/PostCommentRepository.java similarity index 71% rename from src/main/java/run/halo/app/repository/CommentRepository.java rename to src/main/java/run/halo/app/repository/PostCommentRepository.java index 860d284d..e34d9065 100644 --- a/src/main/java/run/halo/app/repository/CommentRepository.java +++ b/src/main/java/run/halo/app/repository/PostCommentRepository.java @@ -2,21 +2,21 @@ package run.halo.app.repository; import org.springframework.data.jpa.repository.Query; 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.repository.base.BaseCommentRepository; import java.util.List; /** - * Comment repository. + * PostComment repository. * * @author johnniang * @date 3/21/19 */ -public interface CommentRepository extends BaseCommentRepository { +public interface PostCommentRepository extends BaseCommentRepository { - @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 @Override List countByPostIds(@NonNull Iterable postIds); diff --git a/src/main/java/run/halo/app/repository/base/BaseCommentRepository.java b/src/main/java/run/halo/app/repository/base/BaseCommentRepository.java index 9407c671..bb9721be 100644 --- a/src/main/java/run/halo/app/repository/base/BaseCommentRepository.java +++ b/src/main/java/run/halo/app/repository/base/BaseCommentRepository.java @@ -3,6 +3,7 @@ package run.halo.app.repository.base; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaSpecificationExecutor; +import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.NoRepositoryBean; import org.springframework.lang.NonNull; import org.springframework.lang.Nullable; diff --git a/src/main/java/run/halo/app/service/CommentService.java b/src/main/java/run/halo/app/service/PostCommentService.java similarity index 56% rename from src/main/java/run/halo/app/service/CommentService.java rename to src/main/java/run/halo/app/service/PostCommentService.java index fa440b95..b7f5161d 100644 --- a/src/main/java/run/halo/app/service/CommentService.java +++ b/src/main/java/run/halo/app/service/PostCommentService.java @@ -3,19 +3,18 @@ package run.halo.app.service; import org.springframework.data.domain.Page; import org.springframework.lang.NonNull; import org.springframework.lang.Nullable; -import run.halo.app.model.entity.Comment; -import run.halo.app.model.params.CommentParam; -import run.halo.app.model.vo.CommentWithPostVO; +import run.halo.app.model.entity.PostComment; +import run.halo.app.model.vo.PostCommentWithPostVO; import run.halo.app.service.base.BaseCommentService; import java.util.List; /** - * Comment service. + * PostComment service. * * @author johnniang */ -public interface CommentService extends BaseCommentService { +public interface PostCommentService extends BaseCommentService { /** * Converts to with post vo. @@ -24,14 +23,14 @@ public interface CommentService extends BaseCommentService { * @return a page of comment with post vo */ @NonNull - Page convertToWithPostVo(@NonNull Page commentPage); + Page convertToWithPostVo(@NonNull Page commentPage); /** * Converts to with post vo * - * @param comments comment list + * @param postComments comment list * @return a list of comment with post vo */ @NonNull - List convertToWithPostVo(@Nullable List comments); + List convertToWithPostVo(@Nullable List postComments); } diff --git a/src/main/java/run/halo/app/service/impl/CommentServiceImpl.java b/src/main/java/run/halo/app/service/impl/PostCommentServiceImpl.java similarity index 51% rename from src/main/java/run/halo/app/service/impl/CommentServiceImpl.java rename to src/main/java/run/halo/app/service/impl/PostCommentServiceImpl.java index 24424569..846aeb57 100644 --- a/src/main/java/run/halo/app/service/impl/CommentServiceImpl.java +++ b/src/main/java/run/halo/app/service/impl/PostCommentServiceImpl.java @@ -9,12 +9,12 @@ import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; import run.halo.app.exception.NotFoundException; 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.vo.CommentWithPostVO; -import run.halo.app.repository.CommentRepository; +import run.halo.app.model.vo.PostCommentWithPostVO; +import run.halo.app.repository.PostCommentRepository; 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.utils.ServiceUtils; @@ -25,56 +25,56 @@ import java.util.Set; import java.util.stream.Collectors; /** - * CommentService implementation class + * PostCommentService implementation class * * @author : RYAN0UP * @date : 2019-03-14 */ @Slf4j @Service -public class CommentServiceImpl extends BaseCommentServiceImpl implements CommentService { +public class PostCommentServiceImpl extends BaseCommentServiceImpl implements PostCommentService { - private final CommentRepository commentRepository; + private final PostCommentRepository postCommentRepository; private final PostRepository postRepository; - public CommentServiceImpl(CommentRepository commentRepository, - PostRepository postRepository, - OptionService optionService, - ApplicationEventPublisher eventPublisher) { - super(commentRepository, optionService, eventPublisher); - this.commentRepository = commentRepository; + public PostCommentServiceImpl(PostCommentRepository postCommentRepository, + PostRepository postRepository, + OptionService optionService, + ApplicationEventPublisher eventPublisher) { + super(postCommentRepository, optionService, eventPublisher); + this.postCommentRepository = postCommentRepository; this.postRepository = postRepository; } @Override - public Page convertToWithPostVo(Page commentPage) { - Assert.notNull(commentPage, "Comment page must not be null"); + public Page convertToWithPostVo(Page commentPage) { + Assert.notNull(commentPage, "PostComment page must not be null"); return new PageImpl<>(convertToWithPostVo(commentPage.getContent()), commentPage.getPageable(), commentPage.getTotalElements()); } @Override - public List convertToWithPostVo(List comments) { - if (CollectionUtils.isEmpty(comments)) { + public List convertToWithPostVo(List postComments) { + if (CollectionUtils.isEmpty(postComments)) { return Collections.emptyList(); } // Fetch goods ids - Set postIds = ServiceUtils.fetchProperty(comments, Comment::getPostId); + Set postIds = ServiceUtils.fetchProperty(postComments, PostComment::getPostId); // Get all posts Map postMap = ServiceUtils.convertToMap(postRepository.findAllById(postIds), Post::getId); - return comments.stream().map(comment -> { + return postComments.stream().map(comment -> { // Convert to vo - CommentWithPostVO commentWithPostVO = new CommentWithPostVO().convertFrom(comment); + PostCommentWithPostVO postCommentWithPostVO = new PostCommentWithPostVO().convertFrom(comment); // 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()); } diff --git a/src/main/java/run/halo/app/service/impl/PostServiceImpl.java b/src/main/java/run/halo/app/service/impl/PostServiceImpl.java index 505911e6..9c0bd486 100644 --- a/src/main/java/run/halo/app/service/impl/PostServiceImpl.java +++ b/src/main/java/run/halo/app/service/impl/PostServiceImpl.java @@ -60,7 +60,7 @@ public class PostServiceImpl extends BasePostServiceImpl implements PostSe private final PostCategoryService postCategoryService; - private final CommentService commentService; + private final PostCommentService postCommentService; private final ApplicationEventPublisher eventPublisher; @@ -69,7 +69,7 @@ public class PostServiceImpl extends BasePostServiceImpl implements PostSe CategoryService categoryService, PostTagService postTagService, PostCategoryService postCategoryService, - CommentService commentService, + PostCommentService postCommentService, ApplicationEventPublisher eventPublisher) { super(postRepository); this.postRepository = postRepository; @@ -77,7 +77,7 @@ public class PostServiceImpl extends BasePostServiceImpl implements PostSe this.categoryService = categoryService; this.postTagService = postTagService; this.postCategoryService = postCategoryService; - this.commentService = commentService; + this.postCommentService = postCommentService; this.eventPublisher = eventPublisher; } @@ -369,7 +369,7 @@ public class PostServiceImpl extends BasePostServiceImpl implements PostSe Map> categoryListMap = postCategoryService.listCategoryListMap(postIds); // Get comment count - Map commentCountMap = commentService.countByPostIds(postIds); + Map commentCountMap = postCommentService.countByPostIds(postIds); return postPage.map(post -> { -- GitLab