mirror of https://github.com/halo-dev/halo
Fix null pointer exception
parent
47a0f40ce1
commit
b6f29c0bac
|
@ -135,6 +135,9 @@ public class Post extends BaseEntity {
|
|||
super.prePersist();
|
||||
id = null;
|
||||
editTime = getCreateTime();
|
||||
if (type == null) {
|
||||
type = PostType.POST;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import cc.ryanc.halo.model.dto.base.InputConverter;
|
|||
import cc.ryanc.halo.model.entity.Post;
|
||||
import cc.ryanc.halo.model.enums.PostCreateFrom;
|
||||
import cc.ryanc.halo.model.enums.PostStatus;
|
||||
import cc.ryanc.halo.model.enums.PostType;
|
||||
import cc.ryanc.halo.utils.HaloUtils;
|
||||
import cn.hutool.crypto.digest.BCrypt;
|
||||
import lombok.Data;
|
||||
|
@ -70,6 +71,9 @@ public class PostParam implements InputConverter<Post> {
|
|||
post.setPassword(BCrypt.hashpw(password, BCrypt.gensalt()));
|
||||
}
|
||||
|
||||
// Set post type to
|
||||
post.setType(PostType.POST);
|
||||
|
||||
return post;
|
||||
}
|
||||
|
||||
|
@ -89,5 +93,6 @@ public class PostParam implements InputConverter<Post> {
|
|||
if (StringUtils.isNotBlank(password)) {
|
||||
post.setPassword(BCrypt.hashpw(password, BCrypt.gensalt()));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,10 +28,7 @@ import org.springframework.stereotype.Service;
|
|||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
|
@ -135,13 +132,21 @@ public class PostServiceImpl extends AbstractCrudService<Post, Integer> implemen
|
|||
return postPage.map(post -> {
|
||||
PostListVO postListVO = new PostListVO().convertFrom(post);
|
||||
|
||||
Optional.ofNullable(tagListMap.get(post.getId())).orElseGet(LinkedList::new);
|
||||
|
||||
// Set tags
|
||||
List<TagOutputDTO> tagOutputDTOS = tagListMap.get(post.getId()).stream().map(tag -> (TagOutputDTO) new TagOutputDTO().convertFrom(tag)).collect(Collectors.toList());
|
||||
postListVO.setTags(tagOutputDTOS);
|
||||
postListVO.setTags(Optional.ofNullable(tagListMap.get(post.getId()))
|
||||
.orElseGet(LinkedList::new)
|
||||
.stream()
|
||||
.map(tag -> new TagOutputDTO().<TagOutputDTO>convertFrom(tag))
|
||||
.collect(Collectors.toList()));
|
||||
|
||||
// Set categories
|
||||
List<CategoryOutputDTO> categoryOutputDTOS = categoryListMap.get(post.getId()).stream().map(category -> (CategoryOutputDTO) new CategoryOutputDTO().convertFrom(category)).collect(Collectors.toList());
|
||||
postListVO.setCategories(categoryOutputDTOS);
|
||||
postListVO.setCategories(Optional.ofNullable(categoryListMap.get(post.getId()))
|
||||
.orElseGet(LinkedList::new)
|
||||
.stream()
|
||||
.map(category -> new CategoryOutputDTO().<CategoryOutputDTO>convertFrom(category))
|
||||
.collect(Collectors.toList()));
|
||||
|
||||
// Set comment count
|
||||
postListVO.setCommentCount(commentCountMap.getOrDefault(post.getId(), 0L));
|
||||
|
|
|
@ -43,8 +43,12 @@ public class PostController {
|
|||
|
||||
@GetMapping("status/{status}")
|
||||
@ApiOperation("Gets a page of post by post status")
|
||||
public Page<PostSimpleOutputDTO> pageByStatus(@PathVariable(name = "status") PostStatus status,
|
||||
@PageableDefault(sort = "updateTime", direction = DESC) Pageable pageable) {
|
||||
public Page<? extends PostSimpleOutputDTO> pageByStatus(@PathVariable(name = "status") PostStatus status,
|
||||
@RequestParam(value = "more_info", required = false, defaultValue = "false") Boolean moreInfo,
|
||||
@PageableDefault(sort = "updateTime", direction = DESC) Pageable pageable) {
|
||||
if (moreInfo) {
|
||||
return postService.pageListVoBy(status, PostType.POST, pageable);
|
||||
}
|
||||
return postService.pageSimpleDtoByStatus(status, PostType.POST, pageable);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue