提交 c3985cf9 编写于 作者: J johnniang

Rename comment to post comment

上级 c9bfd11c
......@@ -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();
......
......@@ -6,60 +6,53 @@ 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.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.CommentWithPostVO;
import run.halo.app.service.CommentService;
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;
/**
* Comment controller.
* Post comment controller.
*
* @author johnniang
* @date 3/19/19
*/
@RestController
@RequestMapping("/api/admin/comments")
public class CommentController {
@RequestMapping("/api/admin/posts/comments")
public class PostCommentController {
private final CommentService commentService;
private final PostCommentService postCommentService;
public CommentController(CommentService commentService) {
this.commentService = commentService;
public PostCommentController(PostCommentService postCommentService) {
this.postCommentService = postCommentService;
}
@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);
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<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);
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) {
Comment createdComment = commentService.createBy(commentParam);
return commentService.convertTo(createdComment);
PostComment createdPostComment = postCommentService.createBy(commentParam);
return postCommentService.convertTo(createdPostComment);
}
@PutMapping("{commentId:\\d+}/status/{status}")
......@@ -67,16 +60,16 @@ public class CommentController {
public BaseCommentDTO updateStatusBy(@PathVariable("commentId") Long commentId,
@PathVariable("status") CommentStatus status) {
// Update comment status
Comment updatedComment = commentService.updateStatus(commentId, status);
PostComment updatedPostComment = postCommentService.updateStatus(commentId, status);
return commentService.convertTo(updatedComment);
return postCommentService.convertTo(updatedPostComment);
}
@DeleteMapping("{commentId:\\d+}")
@ApiOperation("Deletes comment permanently and recursively")
public BaseCommentDTO deleteBy(@PathVariable("commentId") Long commentId) {
Comment deletedComment = commentService.removeById(commentId);
PostComment deletedPostComment = postCommentService.removeById(commentId);
return commentService.convertTo(deletedComment);
return postCommentService.convertTo(deletedPostComment);
}
}
......@@ -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
......
......@@ -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<Category> categories = postCategoryService.listCategoryBy(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);
model.addAttribute("is_post", true);
......
......@@ -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;
}
......
......@@ -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));
}
}
......@@ -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<BaseCommentVO> 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<BaseCommentWithParentVO> 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")
......
......@@ -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;
}
......
......@@ -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;
}
......
......@@ -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<String, Object> 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
}
......
......@@ -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
......
......@@ -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
......
......@@ -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
......
......@@ -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 {
}
......@@ -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
......
......@@ -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;
......
......@@ -19,26 +19,26 @@ import java.lang.reflect.ParameterizedType;
@Data
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}")
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
......
......@@ -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<Comment> {
public class CommentParam extends BaseCommentParam<PostComment> {
}
......@@ -5,7 +5,7 @@ import lombok.Data;
import lombok.NoArgsConstructor;
/**
* Comment count projection
* PostComment count projection
*
* @author johnniang
* @date 3/22/19
......
......@@ -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
......
......@@ -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;
}
......@@ -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<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
@Override
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.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;
......
......@@ -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<Comment> {
public interface PostCommentService extends BaseCommentService<PostComment> {
/**
* Converts to with post vo.
......@@ -24,14 +23,14 @@ public interface CommentService extends BaseCommentService<Comment> {
* @return a page of comment with post vo
*/
@NonNull
Page<CommentWithPostVO> convertToWithPostVo(@NonNull Page<Comment> commentPage);
Page<PostCommentWithPostVO> convertToWithPostVo(@NonNull Page<PostComment> commentPage);
/**
* Converts to with post vo
*
* @param comments comment list
* @param postComments comment list
* @return a list of comment with post vo
*/
@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 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<Comment> implements CommentService {
public class PostCommentServiceImpl extends BaseCommentServiceImpl<PostComment> 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<CommentWithPostVO> convertToWithPostVo(Page<Comment> commentPage) {
Assert.notNull(commentPage, "Comment page must not be null");
public Page<PostCommentWithPostVO> convertToWithPostVo(Page<PostComment> commentPage) {
Assert.notNull(commentPage, "PostComment page must not be null");
return new PageImpl<>(convertToWithPostVo(commentPage.getContent()), commentPage.getPageable(), commentPage.getTotalElements());
}
@Override
public List<CommentWithPostVO> convertToWithPostVo(List<Comment> comments) {
if (CollectionUtils.isEmpty(comments)) {
public List<PostCommentWithPostVO> convertToWithPostVo(List<PostComment> postComments) {
if (CollectionUtils.isEmpty(postComments)) {
return Collections.emptyList();
}
// Fetch goods ids
Set<Integer> postIds = ServiceUtils.fetchProperty(comments, Comment::getPostId);
Set<Integer> postIds = ServiceUtils.fetchProperty(postComments, PostComment::getPostId);
// Get all posts
Map<Integer, Post> 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());
}
......
......@@ -60,7 +60,7 @@ public class PostServiceImpl extends BasePostServiceImpl<Post> 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<Post> 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<Post> 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<Post> implements PostSe
Map<Integer, List<Category>> categoryListMap = postCategoryService.listCategoryListMap(postIds);
// Get comment count
Map<Integer, Long> commentCountMap = commentService.countByPostIds(postIds);
Map<Integer, Long> commentCountMap = postCommentService.countByPostIds(postIds);
return postPage.map(post -> {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册