mirror of https://github.com/halo-dev/halo
Remove useless post dtos
parent
16476f5a9b
commit
da52405843
|
@ -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<? extends TagDTO> 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<PostSimpleDTO> listPostsBy(@PathVariable("slugName") String slugName,
|
||||
@PageableDefault(sort = "updateTime", direction = DESC) Pageable pageable) {
|
||||
public Page<BasePostSimpleDTO> 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<Post> postPage = postTagService.pagePostsBy(tag.getId(), pageable);
|
||||
return postService.convertToSimple(postPage);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ public interface OutputConverter<DTO extends OutputConverter<DTO, DOMAIN>, DOMAI
|
|||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@NonNull
|
||||
default <T extends DTO> T convertFrom(DOMAIN domain) {
|
||||
default <T extends DTO> T convertFrom(@NonNull DOMAIN domain) {
|
||||
|
||||
updateProperties(domain, this);
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
|
@ -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<PostMinimalDTO, BasePost> {
|
||||
|
||||
private Integer id;
|
||||
|
||||
private String title;
|
||||
|
||||
private PostStatus status;
|
||||
|
||||
private String url;
|
||||
|
||||
private PostType type;
|
||||
|
||||
private Date updateTime;
|
||||
|
||||
private Date createTime;
|
||||
|
||||
private Date editTime;
|
||||
}
|
|
@ -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;
|
||||
}
|
|
@ -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 {
|
||||
|
||||
}
|
|
@ -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 {
|
||||
}
|
|
@ -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 {
|
||||
}
|
|
@ -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<PostMinimalDTO> posts;
|
||||
private List<BasePostMinimalDTO> posts;
|
||||
|
||||
public static class ArchiveComparator implements Comparator<ArchiveYearVO> {
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
||||
/**
|
||||
|
|
|
@ -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<PostComment>
|
|||
// Get all posts
|
||||
Map<Integer, Post> 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
|
||||
|
|
|
@ -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<Post> 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<Post> 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<Post> implements PostSe
|
|||
// Get comment count
|
||||
Map<Integer, Long> commentCountMap = postCommentService.countByPostIds(postIds);
|
||||
|
||||
|
||||
return postPage.map(post -> {
|
||||
PostListVO postListVO = new PostListVO().convertFrom(post);
|
||||
|
||||
|
@ -362,24 +358,6 @@ public class PostServiceImpl extends BasePostServiceImpl<Post> 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<PostMinimalDTO> convertTo(@NonNull List<Post> posts) {
|
||||
if (CollectionUtils.isEmpty(posts)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
// Convert
|
||||
return posts.stream()
|
||||
.map(post -> new PostMinimalDTO().<PostMinimalDTO>convertFrom(post))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts to post detail vo.
|
||||
*
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue