Rename CommentVO to CommentListVO

pull/137/head
johnniang 2019-03-25 15:29:47 +08:00
parent 22baaa0972
commit 7a679d0f8e
4 changed files with 17 additions and 16 deletions

View File

@ -14,7 +14,7 @@ import lombok.ToString;
@Data @Data
@ToString @ToString
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
public class CommentVO extends CommentOutputDTO { public class CommentListVO extends CommentOutputDTO {
private PostMinimalOutputDTO post; private PostMinimalOutputDTO post;
} }

View File

@ -3,7 +3,7 @@ package cc.ryanc.halo.service;
import cc.ryanc.halo.model.entity.Comment; import cc.ryanc.halo.model.entity.Comment;
import cc.ryanc.halo.model.enums.CommentStatus; import cc.ryanc.halo.model.enums.CommentStatus;
import cc.ryanc.halo.model.params.CommentParam; import cc.ryanc.halo.model.params.CommentParam;
import cc.ryanc.halo.model.vo.CommentVO; import cc.ryanc.halo.model.vo.CommentListVO;
import cc.ryanc.halo.service.base.CrudService; import cc.ryanc.halo.service.base.CrudService;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
@ -36,7 +36,7 @@ public interface CommentService extends CrudService<Comment, Long> {
* @return a page of comments * @return a page of comments
*/ */
@NonNull @NonNull
Page<CommentVO> pageLatest(int top); Page<CommentListVO> pageLatest(int top);
/** /**
* Pages comments. * Pages comments.
@ -46,7 +46,7 @@ public interface CommentService extends CrudService<Comment, Long> {
* @return a page of comment * @return a page of comment
*/ */
@NonNull @NonNull
Page<CommentVO> pageBy(@NonNull CommentStatus status, @NonNull Pageable pageable); Page<CommentListVO> pageBy(@NonNull CommentStatus status, @NonNull Pageable pageable);
/** /**
* Lists comments by post id. * Lists comments by post id.

View File

@ -8,7 +8,7 @@ import cc.ryanc.halo.model.enums.BlogProperties;
import cc.ryanc.halo.model.enums.CommentStatus; import cc.ryanc.halo.model.enums.CommentStatus;
import cc.ryanc.halo.model.params.CommentParam; import cc.ryanc.halo.model.params.CommentParam;
import cc.ryanc.halo.model.projection.CommentCountProjection; import cc.ryanc.halo.model.projection.CommentCountProjection;
import cc.ryanc.halo.model.vo.CommentVO; import cc.ryanc.halo.model.vo.CommentListVO;
import cc.ryanc.halo.repository.CommentRepository; import cc.ryanc.halo.repository.CommentRepository;
import cc.ryanc.halo.repository.PostRepository; import cc.ryanc.halo.repository.PostRepository;
import cc.ryanc.halo.service.CommentService; import cc.ryanc.halo.service.CommentService;
@ -59,7 +59,7 @@ public class CommentServiceImpl extends AbstractCrudService<Comment, Long> imple
} }
@Override @Override
public Page<CommentVO> pageLatest(int top) { public Page<CommentListVO> pageLatest(int top) {
Assert.isTrue(top > 0, "Top number must not be less than 0"); Assert.isTrue(top > 0, "Top number must not be less than 0");
// Build page request // Build page request
@ -69,7 +69,7 @@ public class CommentServiceImpl extends AbstractCrudService<Comment, Long> imple
} }
@Override @Override
public Page<CommentVO> pageBy(CommentStatus status, Pageable pageable) { public Page<CommentListVO> pageBy(CommentStatus status, Pageable pageable) {
Assert.notNull(status, "Comment status must not be null"); Assert.notNull(status, "Comment status must not be null");
Assert.notNull(pageable, "Page info must not be null"); Assert.notNull(pageable, "Page info must not be null");
@ -152,7 +152,7 @@ public class CommentServiceImpl extends AbstractCrudService<Comment, Long> imple
* @return a page of comment vo * @return a page of comment vo
*/ */
@NonNull @NonNull
private Page<CommentVO> convertBy(@NonNull Page<Comment> commentPage) { private Page<CommentListVO> convertBy(@NonNull Page<Comment> commentPage) {
Assert.notNull(commentPage, "Comment page must not be null"); Assert.notNull(commentPage, "Comment page must not be null");
return new PageImpl<>(convertBy(commentPage.getContent()), commentPage.getPageable(), commentPage.getTotalElements()); return new PageImpl<>(convertBy(commentPage.getContent()), commentPage.getPageable(), commentPage.getTotalElements());
@ -165,7 +165,7 @@ public class CommentServiceImpl extends AbstractCrudService<Comment, Long> imple
* @return a list of comment vo * @return a list of comment vo
*/ */
@NonNull @NonNull
private List<CommentVO> convertBy(@Nullable List<Comment> comments) { private List<CommentListVO> convertBy(@Nullable List<Comment> comments) {
if (CollectionUtils.isEmpty(comments)) { if (CollectionUtils.isEmpty(comments)) {
return Collections.emptyList(); return Collections.emptyList();
} }
@ -178,12 +178,12 @@ public class CommentServiceImpl extends AbstractCrudService<Comment, Long> imple
return comments.stream().map(comment -> { return comments.stream().map(comment -> {
// Convert to vo // Convert to vo
CommentVO commentVO = new CommentVO().convertFrom(comment); CommentListVO commentListVO = new CommentListVO().convertFrom(comment);
// Get post and set to the vo // Get post and set to the vo
commentVO.setPost(new PostMinimalOutputDTO().convertFrom(postMap.get(comment.getPostId()))); commentListVO.setPost(new PostMinimalOutputDTO().convertFrom(postMap.get(comment.getPostId())));
return commentVO; return commentListVO;
}).collect(Collectors.toList()); }).collect(Collectors.toList());
} }

View File

@ -3,7 +3,7 @@ package cc.ryanc.halo.web.controller.admin.api;
import cc.ryanc.halo.model.dto.CommentOutputDTO; import cc.ryanc.halo.model.dto.CommentOutputDTO;
import cc.ryanc.halo.model.enums.CommentStatus; import cc.ryanc.halo.model.enums.CommentStatus;
import cc.ryanc.halo.model.params.CommentParam; import cc.ryanc.halo.model.params.CommentParam;
import cc.ryanc.halo.model.vo.CommentVO; import cc.ryanc.halo.model.vo.CommentListVO;
import cc.ryanc.halo.service.CommentService; import cc.ryanc.halo.service.CommentService;
import cc.ryanc.halo.service.OptionService; import cc.ryanc.halo.service.OptionService;
import cc.ryanc.halo.service.PostService; import cc.ryanc.halo.service.PostService;
@ -45,13 +45,13 @@ public class CommentController {
@GetMapping("latest") @GetMapping("latest")
@ApiOperation("Pages latest comments") @ApiOperation("Pages latest comments")
public List<CommentVO> pageLatest(@RequestParam(name = "top", defaultValue = "10") int top) { public List<CommentListVO> pageLatest(@RequestParam(name = "top", defaultValue = "10") int top) {
return commentService.pageLatest(top).getContent(); return commentService.pageLatest(top).getContent();
} }
@GetMapping("status/{status}") @GetMapping("status/{status}")
public Page<CommentVO> pageBy(@PageableDefault(sort = "updateTime", direction = DESC) Pageable pageable, public Page<CommentListVO> pageBy(@PageableDefault(sort = "updateTime", direction = DESC) Pageable pageable,
@PathVariable("status") CommentStatus status) { @PathVariable("status") CommentStatus status) {
return commentService.pageBy(status, pageable); return commentService.pageBy(status, pageable);
} }
@ -59,4 +59,5 @@ public class CommentController {
public CommentOutputDTO createBy(@Valid @RequestBody CommentParam commentParam, HttpServletRequest request) { public CommentOutputDTO createBy(@Valid @RequestBody CommentParam commentParam, HttpServletRequest request) {
return new CommentOutputDTO().convertFrom(commentService.createBy(commentParam, request)); return new CommentOutputDTO().convertFrom(commentService.createBy(commentParam, request));
} }
} }