提交 541d5072 authored 作者: Whispa's avatar Whispa

commit

上级 e2bf7e30
......@@ -151,13 +151,15 @@ public class PostController {
}
@GetMapping("/community/{postId}")
public Optional<Post> findPost(@PathVariable(value = "postId") String id) {
public Post findPost(@PathVariable(value = "postId") String id) {
Optional<Post> byId = repository.findById(id);
if (byId.isPresent()) {
Post post = byId.get();
visitPost(post);
post.retrieveAll = true;
return post;
}
return byId;
return null;
}
private List<Post> postList(List<Post> postList, String userId) {
......
......@@ -40,6 +40,9 @@ public class Post extends Model {
@Transient
public boolean liked = false;
@Transient
public boolean retrieveAll = false;
@OneToMany(mappedBy = "post",cascade = CascadeType.ALL)
public List<Content> contentList = new ArrayList<>();
......@@ -54,6 +57,14 @@ public class Post extends Model {
return tags;
}
public String getUsername() {
return userInfo != null ? userInfo.display() : "";
}
public String getAvatar() {
return userInfo != null ? userInfo.getAvatar() : "";
}
public TbCfUserInfo getUser() {
return userInfo;
}
......@@ -102,4 +113,20 @@ public class Post extends Model {
public List<Hashtag> hashtags() {
return hashtagList.stream().map(PostHashtag::getHashtag).collect(Collectors.toList());
}
@JsonProperty
public List<String> items() {
return contentList.stream().map(Content::getContent).collect(Collectors.toList());
}
public TbCfUserInfo getUserInfo() {
return retrieveAll ? userInfo : null;
}
public List<Content> getContentList() {
return retrieveAll ? contentList : new ArrayList<>();
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论