feat: add convert meta list to map method.

pull/755/head
ruibaby 2019-12-01 20:16:36 +08:00
parent 5819fd735a
commit b2a6d06173
4 changed files with 49 additions and 10 deletions

View File

@ -163,15 +163,15 @@ public class ContentArchiveController {
List<Category> categories = postCategoryService.listCategoriesBy(post.getId());
List<Tag> tags = postTagService.listTagsBy(post.getId());
List<PostMeta> postMetas = postMetaService.listPostMetasBy(post.getId());
List<PostMeta> metas = postMetaService.listPostMetasBy(post.getId());
Page<BaseCommentVO> comments = postCommentService.pageVosBy(post.getId(), PageRequest.of(cp, optionService.getCommentPageSize(), sort));
model.addAttribute("is_post", true);
model.addAttribute("post", postService.convertToDetailVo(post));
model.addAttribute("categories", categories);
model.addAttribute("postMetas", postMetas);
model.addAttribute("tags", tags);
model.addAttribute("metas", postMetaService.convertToMap(metas));
model.addAttribute("comments", comments);
if (preview) {

View File

@ -1,7 +1,6 @@
package run.halo.app.service;
import org.springframework.lang.NonNull;
import org.springframework.lang.Nullable;
import run.halo.app.model.dto.PostMetaDTO;
import run.halo.app.model.entity.PostMeta;
import run.halo.app.service.base.BaseMetaService;
@ -19,17 +18,55 @@ import java.util.Set;
* @date 2019-08-04
*/
public interface PostMetaService extends BaseMetaService<PostMeta> {
List<PostMeta> createOrUpdateByPostId(Integer id, Set<PostMeta> postMetas);
List<PostMeta> listPostMetasBy(Integer id);
/**
* Creates by post metas and post id.
*
* @param postId post id must not be null
* @param postMetas post metas must not be null
* @return a list of post meta
*/
List<PostMeta> createOrUpdateByPostId(@NonNull Integer postId, @NonNull Set<PostMeta> postMetas);
List<PostMeta> removeByPostId(Integer postId);
/**
* Lists post metas by post id.
*
* @param postId post id must not be null
* @return a list of post meta
*/
List<PostMeta> listPostMetasBy(@NonNull Integer postId);
Map<Integer, List<PostMeta>> listPostMetaListMap(Set<Integer> postIds);
/**
* Remove post metas by post id.
*
* @param postId post id must not be null
* @return a list of post meta
*/
List<PostMeta> removeByPostId(@NonNull Integer postId);
/**
* Lists post metas as map.
*
* @param postIds post ids must not be null
* @return a map of post meta
*/
Map<Integer, List<PostMeta>> listPostMetaAsMap(@NonNull Set<Integer> postIds);
/**
* Convert PostMeta to PostMetaDTO.
*
* @param postMeta post meta must not be null
* @return post meta vo
*/
@NonNull
PostMetaDTO convertTo(@NonNull PostMeta postMeta);
/**
* Convert list of PostMeta to list of PostMetaDTO.
*
* @param postMetaList post meta list must not be null
* @return a list of post meta dto
*/
@NonNull
List<PostMetaDTO> convertTo(@Nullable List<PostMeta> postMetaList);
List<PostMetaDTO> convertTo(@NonNull List<PostMeta> postMetaList);
}

View File

@ -47,6 +47,7 @@ public class PostMetaServiceImpl extends BaseMetaServiceImpl<PostMeta> implement
@Override
public List<PostMeta> createOrUpdateByPostId(Integer postId, Set<PostMeta> postMetas) {
Assert.notNull(postId, "Post id must not be null");
Assert.notNull(postMetas, "Post metas must not be null");
if (CollectionUtils.isEmpty(postMetas)) {
return Collections.emptyList();
}
@ -75,7 +76,8 @@ public class PostMetaServiceImpl extends BaseMetaServiceImpl<PostMeta> implement
}
@Override
public Map<Integer, List<PostMeta>> listPostMetaListMap(Set<Integer> postIds) {
public Map<Integer, List<PostMeta>> listPostMetaAsMap(Set<Integer> postIds) {
Assert.notNull(postIds, "Post ids must not be null");
if (CollectionUtils.isEmpty(postIds)) {
return Collections.emptyMap();
}

View File

@ -428,7 +428,7 @@ public class PostServiceImpl extends BasePostServiceImpl<Post> implements PostSe
Map<Integer, Long> commentCountMap = postCommentService.countByPostIds(postIds);
// Get post meta list map
Map<Integer, List<PostMeta>> postMetaListMap = postMetaService.listPostMetaListMap(postIds);
Map<Integer, List<PostMeta>> postMetaListMap = postMetaService.listPostMetaAsMap(postIds);
return postPage.map(post -> {
PostListVO postListVO = new PostListVO().convertFrom(post);