diff --git a/src/main/java/run/halo/app/controller/content/api/TagController.java b/src/main/java/run/halo/app/controller/content/api/TagController.java index 16487bcd7b7c7335c949e0482de0f5c1bcf8a83b..b2f5e95cbc5fb7fbbefb719cbb5f099772a8eb84 100644 --- a/src/main/java/run/halo/app/controller/content/api/TagController.java +++ b/src/main/java/run/halo/app/controller/content/api/TagController.java @@ -1,10 +1,5 @@ package run.halo.app.controller.content.api; -import run.halo.app.model.dto.TagDTO; -import run.halo.app.model.dto.post.PostSimpleDTO; -import run.halo.app.model.entity.Tag; -import run.halo.app.service.PostTagService; -import run.halo.app.service.TagService; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import org.springframework.data.domain.Page; @@ -13,6 +8,13 @@ import org.springframework.data.domain.Sort; import org.springframework.data.web.PageableDefault; import org.springframework.data.web.SortDefault; import org.springframework.web.bind.annotation.*; +import run.halo.app.model.dto.TagDTO; +import run.halo.app.model.dto.post.BasePostSimpleDTO; +import run.halo.app.model.entity.Post; +import run.halo.app.model.entity.Tag; +import run.halo.app.service.PostService; +import run.halo.app.service.PostTagService; +import run.halo.app.service.TagService; import java.util.List; @@ -32,16 +34,21 @@ public class TagController { private final PostTagService postTagService; - public TagController(TagService tagService, PostTagService postTagService) { + private final PostService postService; + + public TagController(TagService tagService, + PostTagService postTagService, + PostService postService) { this.tagService = tagService; this.postTagService = postTagService; + this.postService = postService; } @GetMapping @ApiOperation("Lists tags") public List listTags(@SortDefault(sort = "updateTime", direction = DESC) Sort sort, @ApiParam("If the param is true, post count of tag will be returned") - @RequestParam(name = "more", required = false, defaultValue = "false") Boolean more) { + @RequestParam(name = "more", required = false, defaultValue = "false") Boolean more) { if (more) { return postTagService.listTagWithCountDtos(sort); } @@ -50,12 +57,13 @@ public class TagController { @GetMapping("{slugName}/posts") @ApiOperation("Lists posts by tag slug name") - public Page listPostsBy(@PathVariable("slugName") String slugName, - @PageableDefault(sort = "updateTime", direction = DESC) Pageable pageable) { + public Page listPostsBy(@PathVariable("slugName") String slugName, + @PageableDefault(sort = "updateTime", direction = DESC) Pageable pageable) { // Get tag by slug name Tag tag = tagService.getBySlugNameOfNonNull(slugName); // Get posts, convert and return - return postTagService.pagePostsBy(tag.getId(), pageable).map(post -> new PostSimpleDTO().convertFrom(post)); + Page postPage = postTagService.pagePostsBy(tag.getId(), pageable); + return postService.convertToSimple(postPage); } } diff --git a/src/main/java/run/halo/app/model/dto/base/OutputConverter.java b/src/main/java/run/halo/app/model/dto/base/OutputConverter.java index 359f0fd78975711b69e3880226be622763d58a75..8f2d31d81b1807c7cd5d445e69de0a149cbf59cb 100644 --- a/src/main/java/run/halo/app/model/dto/base/OutputConverter.java +++ b/src/main/java/run/halo/app/model/dto/base/OutputConverter.java @@ -23,7 +23,7 @@ public interface OutputConverter, DOMAI */ @SuppressWarnings("unchecked") @NonNull - default T convertFrom(DOMAIN domain) { + default T convertFrom(@NonNull DOMAIN domain) { updateProperties(domain, this); diff --git a/src/main/java/run/halo/app/model/dto/post/PostDetailDTO.java b/src/main/java/run/halo/app/model/dto/post/PostDetailDTO.java deleted file mode 100644 index eaf8eb79fa5389e7b437c892013efe7073a85cd6..0000000000000000000000000000000000000000 --- a/src/main/java/run/halo/app/model/dto/post/PostDetailDTO.java +++ /dev/null @@ -1,21 +0,0 @@ -package run.halo.app.model.dto.post; - -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.ToString; - -/** - * Post detail output dto. - * - * @author johnniang - */ -@Data -@ToString -@EqualsAndHashCode(callSuper = true) -@Deprecated -public class PostDetailDTO extends PostSimpleDTO { - - private String originalContent; - - private String formatContent; -} diff --git a/src/main/java/run/halo/app/model/dto/post/PostMinimalDTO.java b/src/main/java/run/halo/app/model/dto/post/PostMinimalDTO.java deleted file mode 100644 index d883158a30b08ce0dd30ede45618f924f92442d5..0000000000000000000000000000000000000000 --- a/src/main/java/run/halo/app/model/dto/post/PostMinimalDTO.java +++ /dev/null @@ -1,39 +0,0 @@ -package run.halo.app.model.dto.post; - -import run.halo.app.model.dto.base.OutputConverter; -import run.halo.app.model.entity.BasePost; -import run.halo.app.model.enums.PostStatus; -import run.halo.app.model.enums.PostType; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.ToString; - -import java.util.Date; - -/** - * Post minimal output dto. - * - * @author johnniang - */ -@Data -@ToString -@EqualsAndHashCode -@Deprecated -public class PostMinimalDTO implements OutputConverter { - - private Integer id; - - private String title; - - private PostStatus status; - - private String url; - - private PostType type; - - private Date updateTime; - - private Date createTime; - - private Date editTime; -} diff --git a/src/main/java/run/halo/app/model/dto/post/PostSimpleDTO.java b/src/main/java/run/halo/app/model/dto/post/PostSimpleDTO.java deleted file mode 100644 index 99d286e4df398f69ae2af00e19f0a6883272635d..0000000000000000000000000000000000000000 --- a/src/main/java/run/halo/app/model/dto/post/PostSimpleDTO.java +++ /dev/null @@ -1,37 +0,0 @@ -package run.halo.app.model.dto.post; - -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.ToString; -import run.halo.app.model.enums.PostCreateFrom; -import run.halo.app.model.enums.PostType; - -/** - * Page simple output dto. - * - * @author johnniang - */ -@Data -@ToString -@EqualsAndHashCode(callSuper = true) -@Deprecated -public class PostSimpleDTO extends PostMinimalDTO { - - private PostType type; - - private String summary; - - private String thumbnail; - - private Long visits = 0L; - - private Boolean disallowComment; - - private String template; - - private Integer topPriority = 0; - - private PostCreateFrom createFrom; - - private Long likes = 0L; -} diff --git a/src/main/java/run/halo/app/model/dto/post/SheetDetailDTO.java b/src/main/java/run/halo/app/model/dto/post/SheetDetailDTO.java deleted file mode 100644 index 390f6e2cd7da9a8778337bb42232c0559708e90c..0000000000000000000000000000000000000000 --- a/src/main/java/run/halo/app/model/dto/post/SheetDetailDTO.java +++ /dev/null @@ -1,12 +0,0 @@ -package run.halo.app.model.dto.post; - -/** - * Simple detail dto. - * - * @author johnniang - * @date 19-4-24 - */ -@Deprecated -public class SheetDetailDTO extends PostDetailDTO { - -} diff --git a/src/main/java/run/halo/app/model/dto/post/SheetMinimalDTO.java b/src/main/java/run/halo/app/model/dto/post/SheetMinimalDTO.java deleted file mode 100644 index 252b65035078dfffc85474cf892fce1ce2777bff..0000000000000000000000000000000000000000 --- a/src/main/java/run/halo/app/model/dto/post/SheetMinimalDTO.java +++ /dev/null @@ -1,11 +0,0 @@ -package run.halo.app.model.dto.post; - -/** - * Sheet minimal dto - * - * @author johnniang - * @date 19-4-24 - */ -@Deprecated -public class SheetMinimalDTO extends PostMinimalDTO { -} diff --git a/src/main/java/run/halo/app/model/dto/post/SheetSimpleDTO.java b/src/main/java/run/halo/app/model/dto/post/SheetSimpleDTO.java deleted file mode 100644 index 697c19dad59147f7cab5e516463784575f8a99b5..0000000000000000000000000000000000000000 --- a/src/main/java/run/halo/app/model/dto/post/SheetSimpleDTO.java +++ /dev/null @@ -1,11 +0,0 @@ -package run.halo.app.model.dto.post; - -/** - * Sheet simple dto. - * - * @author johnniang - * @date 19-4-24 - */ -@Deprecated -public class SheetSimpleDTO extends PostSimpleDTO { -} diff --git a/src/main/java/run/halo/app/model/vo/ArchiveYearVO.java b/src/main/java/run/halo/app/model/vo/ArchiveYearVO.java index 170d3399bc675108e000130ebe0001b34c6201ce..525012c862f86a542257995a8278f2dd37364456 100644 --- a/src/main/java/run/halo/app/model/vo/ArchiveYearVO.java +++ b/src/main/java/run/halo/app/model/vo/ArchiveYearVO.java @@ -1,9 +1,9 @@ package run.halo.app.model.vo; -import run.halo.app.model.dto.post.PostMinimalDTO; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.ToString; +import run.halo.app.model.dto.post.BasePostMinimalDTO; import java.util.Comparator; import java.util.List; @@ -21,7 +21,7 @@ public class ArchiveYearVO { private Integer year; - private List posts; + private List posts; public static class ArchiveComparator implements Comparator { diff --git a/src/main/java/run/halo/app/model/vo/PostCommentWithPostVO.java b/src/main/java/run/halo/app/model/vo/PostCommentWithPostVO.java index 193553931caf9423138938edc6e01addda2c4003..17d7c4962b09957f57f385e5be29290a82868629 100644 --- a/src/main/java/run/halo/app/model/vo/PostCommentWithPostVO.java +++ b/src/main/java/run/halo/app/model/vo/PostCommentWithPostVO.java @@ -4,7 +4,7 @@ import lombok.Data; import lombok.EqualsAndHashCode; import lombok.ToString; import run.halo.app.model.dto.BaseCommentDTO; -import run.halo.app.model.dto.post.PostMinimalDTO; +import run.halo.app.model.dto.post.BasePostMinimalDTO; /** * PostComment list with post vo. @@ -16,5 +16,5 @@ import run.halo.app.model.dto.post.PostMinimalDTO; @EqualsAndHashCode(callSuper = true) public class PostCommentWithPostVO extends BaseCommentDTO { - private PostMinimalDTO post; + private BasePostMinimalDTO post; } diff --git a/src/main/java/run/halo/app/model/vo/PostDetailVO.java b/src/main/java/run/halo/app/model/vo/PostDetailVO.java index 9e9e8d8cd085b613efcb31cb5ac3be94abea40a3..f87927319f1252b2286eeb5fb6e017425c108ef1 100644 --- a/src/main/java/run/halo/app/model/vo/PostDetailVO.java +++ b/src/main/java/run/halo/app/model/vo/PostDetailVO.java @@ -1,9 +1,8 @@ package run.halo.app.model.vo; -import run.halo.app.model.dto.post.BasePostDetailDTO; -import run.halo.app.model.dto.post.PostDetailDTO; import lombok.Data; import lombok.EqualsAndHashCode; +import run.halo.app.model.dto.post.BasePostDetailDTO; import java.util.Set; diff --git a/src/main/java/run/halo/app/service/PostService.java b/src/main/java/run/halo/app/service/PostService.java index e026b4599577ebb148d760d0d83a4cad8c5748fc..47609f2c4d6f5e03c7aa0a09c966007f60d4d24b 100755 --- a/src/main/java/run/halo/app/service/PostService.java +++ b/src/main/java/run/halo/app/service/PostService.java @@ -4,8 +4,6 @@ import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.lang.NonNull; import org.springframework.transaction.annotation.Transactional; -import run.halo.app.model.dto.post.PostMinimalDTO; -import run.halo.app.model.dto.post.PostSimpleDTO; import run.halo.app.model.entity.Post; import run.halo.app.model.enums.PostStatus; import run.halo.app.model.params.PostQuery; diff --git a/src/main/java/run/halo/app/service/SheetService.java b/src/main/java/run/halo/app/service/SheetService.java index a3f2f74cbbd48ca5cd7b4c850cfde363edcf36cf..3c580ac0f2d2e49fd412b79b9f53b9f55e907f10 100644 --- a/src/main/java/run/halo/app/service/SheetService.java +++ b/src/main/java/run/halo/app/service/SheetService.java @@ -2,10 +2,9 @@ package run.halo.app.service; import org.springframework.data.domain.Page; import org.springframework.lang.NonNull; -import run.halo.app.model.dto.post.SheetDetailDTO; -import run.halo.app.model.vo.SheetListVO; import run.halo.app.model.entity.Sheet; import run.halo.app.model.enums.PostStatus; +import run.halo.app.model.vo.SheetListVO; import run.halo.app.service.base.BasePostService; /** diff --git a/src/main/java/run/halo/app/service/impl/PostCommentServiceImpl.java b/src/main/java/run/halo/app/service/impl/PostCommentServiceImpl.java index 846aeb57a3ee365bf6cad821cf5d65b5b2e6c0c1..458e9b63dadefaa9077f4c6a286b264b9d7dc55f 100644 --- a/src/main/java/run/halo/app/service/impl/PostCommentServiceImpl.java +++ b/src/main/java/run/halo/app/service/impl/PostCommentServiceImpl.java @@ -8,14 +8,14 @@ import org.springframework.stereotype.Service; 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.PostComment; +import run.halo.app.model.dto.post.BasePostMinimalDTO; import run.halo.app.model.entity.Post; +import run.halo.app.model.entity.PostComment; import run.halo.app.model.vo.PostCommentWithPostVO; import run.halo.app.repository.PostCommentRepository; import run.halo.app.repository.PostRepository; -import run.halo.app.service.PostCommentService; import run.halo.app.service.OptionService; +import run.halo.app.service.PostCommentService; import run.halo.app.utils.ServiceUtils; import java.util.Collections; @@ -67,15 +67,17 @@ public class PostCommentServiceImpl extends BaseCommentServiceImpl // Get all posts Map postMap = ServiceUtils.convertToMap(postRepository.findAllById(postIds), Post::getId); - return postComments.stream().map(comment -> { - // Convert to vo - PostCommentWithPostVO postCommentWithPostVO = new PostCommentWithPostVO().convertFrom(comment); + return postComments.stream() + .filter(comment -> postMap.containsKey(comment.getPostId())) + .map(comment -> { + // Convert to vo + PostCommentWithPostVO postCommentWithPostVO = new PostCommentWithPostVO().convertFrom(comment); - // Get post and set to the vo - postCommentWithPostVO.setPost(new PostMinimalDTO().convertFrom(postMap.get(comment.getPostId()))); + // Get post and set to the vo + postCommentWithPostVO.setPost(new BasePostMinimalDTO().convertFrom(postMap.get(comment.getPostId()))); - return postCommentWithPostVO; - }).collect(Collectors.toList()); + return postCommentWithPostVO; + }).collect(Collectors.toList()); } @Override 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 653a87f5da701bc28a7d3c788a30910c96835012..d4916247b33f28872000d4c7e962a4b0a9ecf6eb 100644 --- a/src/main/java/run/halo/app/service/impl/PostServiceImpl.java +++ b/src/main/java/run/halo/app/service/impl/PostServiceImpl.java @@ -11,13 +11,10 @@ import org.springframework.lang.NonNull; import org.springframework.lang.Nullable; import org.springframework.stereotype.Service; import org.springframework.util.Assert; -import org.springframework.util.CollectionUtils; import run.halo.app.event.logger.LogEvent; import run.halo.app.event.post.PostVisitEvent; import run.halo.app.model.dto.CategoryDTO; import run.halo.app.model.dto.TagDTO; -import run.halo.app.model.dto.post.PostMinimalDTO; -import run.halo.app.model.dto.post.PostSimpleDTO; import run.halo.app.model.entity.*; import run.halo.app.model.enums.LogType; import run.halo.app.model.enums.PostStatus; @@ -240,7 +237,7 @@ public class PostServiceImpl extends BasePostServiceImpl implements PostSe // Build archive ArchiveYearVO archive = new ArchiveYearVO(); archive.setYear(year); - archive.setPosts(convertTo(postList)); + archive.setPosts(convertToMinimal(postList)); // Add archive archives.add(archive); @@ -274,7 +271,7 @@ public class PostServiceImpl extends BasePostServiceImpl implements PostSe ArchiveMonthVO archive = new ArchiveMonthVO(); archive.setYear(year); archive.setMonth(month); - archive.setPosts(convertTo(postList)); + archive.setPosts(convertToMinimal(postList)); archives.add(archive); })); @@ -333,7 +330,6 @@ public class PostServiceImpl extends BasePostServiceImpl implements PostSe // Get comment count Map commentCountMap = postCommentService.countByPostIds(postIds); - return postPage.map(post -> { PostListVO postListVO = new PostListVO().convertFrom(post); @@ -362,24 +358,6 @@ public class PostServiceImpl extends BasePostServiceImpl implements PostSe }); } - /** - * Converts to post minimal output dto. - * - * @param posts a list of post - * @return a list of post minimal output dto - */ - @NonNull - private List convertTo(@NonNull List posts) { - if (CollectionUtils.isEmpty(posts)) { - return Collections.emptyList(); - } - - // Convert - return posts.stream() - .map(post -> new PostMinimalDTO().convertFrom(post)) - .collect(Collectors.toList()); - } - /** * Converts to post detail vo. * diff --git a/src/main/java/run/halo/app/service/impl/SheetServiceImpl.java b/src/main/java/run/halo/app/service/impl/SheetServiceImpl.java index 789d6764c4fb56a16cc11acdaea219d446150bd8..5ccbe11902b608a5c0707c77082edbc7f4338ac1 100644 --- a/src/main/java/run/halo/app/service/impl/SheetServiceImpl.java +++ b/src/main/java/run/halo/app/service/impl/SheetServiceImpl.java @@ -6,10 +6,9 @@ import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; import org.springframework.util.Assert; import run.halo.app.event.post.SheetVisitEvent; -import run.halo.app.model.dto.post.SheetDetailDTO; -import run.halo.app.model.vo.SheetListVO; import run.halo.app.model.entity.Sheet; import run.halo.app.model.enums.PostStatus; +import run.halo.app.model.vo.SheetListVO; import run.halo.app.repository.SheetRepository; import run.halo.app.service.SheetCommentService; import run.halo.app.service.SheetService;