Create list latest by status api for comment.

pull/146/head
ruibaby 2019-05-03 14:34:55 +08:00
parent a6697c5d6b
commit ff7ecc9d09
6 changed files with 37 additions and 10 deletions

View File

@ -8,8 +8,8 @@ import org.springframework.web.bind.annotation.*;
import run.halo.app.model.dto.BaseCommentDTO;
import run.halo.app.model.entity.PostComment;
import run.halo.app.model.enums.CommentStatus;
import run.halo.app.model.params.PostCommentParam;
import run.halo.app.model.params.CommentQuery;
import run.halo.app.model.params.PostCommentParam;
import run.halo.app.model.vo.PostCommentWithPostVO;
import run.halo.app.service.PostCommentService;
@ -48,6 +48,14 @@ public class PostCommentController {
return postCommentService.convertToWithPostVo(content);
}
@GetMapping("latest/{status}")
@ApiOperation("Pages latest comments by status")
public List<PostCommentWithPostVO> pageLatest(@RequestParam(name = "top", defaultValue = "10") int top,
@PathVariable("status") CommentStatus status) {
List<PostComment> content = postCommentService.pageLatest(top, status).getContent();
return postCommentService.convertToWithPostVo(content);
}
@PostMapping
@ApiOperation("Creates a comment (new or reply)")
public BaseCommentDTO createBy(@RequestBody PostCommentParam postCommentParam) {

View File

@ -51,6 +51,16 @@ public interface BaseCommentService<COMMENT extends BaseComment> extends CrudSer
@NonNull
Page<COMMENT> pageLatest(int top);
/**
* Lists latest comments by status
*
* @param top top number must not be less than 0
* @param status status
* @return a page of comments
*/
@NonNull
Page<COMMENT> pageLatest(int top, CommentStatus status);
/**
* Pages comments.
*

View File

@ -78,6 +78,11 @@ public abstract class BaseCommentServiceImpl<COMMENT extends BaseComment> extend
return listAll(ServiceUtils.buildLatestPageable(top));
}
@Override
public Page<COMMENT> pageLatest(int top,CommentStatus status){
return baseCommentRepository.findAllByStatus(status,ServiceUtils.buildLatestPageable(top));
}
@Override
public Page<COMMENT> pageBy(CommentStatus status, Pageable pageable) {

View File

@ -1,3 +1,5 @@
<#if !post.disallowComment>
<#include "/common/comment/comment.ftl">
</#if>
<#macro comment id,type>
<script src="https://unpkg.com/vue"></script>
<script src="/static/js/halo-comment.min.js"></script>
<halo-comment id="${id}" type="${type}"/>
</#macro>

View File

@ -93,6 +93,7 @@
</div>
<div id="comment_widget">
<#include "module/comment.ftl">
<@comment id="${post.id}" type="post" />
</div>
</div>
</div>

View File

@ -1,5 +1,5 @@
<#include "module/macro.ftl">
<@head title="${sheet.title!} · ${options.blog_title!'Anatole'}" keywords="${sheet.title!},${options.seo_keywords!'Anatole'}" description="${sheet.summary!'Anatole'}"></@head>
<@head title="${post.title!} · ${options.blog_title!'Anatole'}" keywords="${post.title!},${options.seo_keywords!'Anatole'}" description="${post.summary!'Anatole'}"></@head>
<#include "module/sidebar.ftl">
<div class="main">
<link href="/${theme.folderName}/source/plugins/prism/prism.css" type="text/css" rel="stylesheet" />
@ -40,19 +40,19 @@
<div class="post animated fadeInDown">
<div class="post-title">
<h3>
<a>${sheet.title!}</a>
<a>${post.title!}</a>
</h3>
</div>
<div class="post-content">
${sheet.formatContent!}
${post.formatContent!}
</div>
<div class="post-footer">
<div class="meta">
<div class="info">
<i class="fa fa-sun-o"></i>
<span class="date">${sheet.createTime?string("yyyy-MM-dd")}</span>
<span class="date">${post.createTime?string("yyyy-MM-dd")}</span>
<i class="fa fa-comment-o"></i>
<a href="${options.blog_url!}/archives/${sheet.url!}#comment_widget">Comments</a>
<a href="${options.blog_url!}/archives/${post.url!}#comment_widget">Comments</a>
</div>
</div>
</div>
@ -67,12 +67,13 @@
class="fa fa-weibo"></a>
</div>
<div class="twitter">
<a href="http://twitter.com/home?status=${options.blog_url!}/archives/${sheet.url!} ,${options.blog_title!},${sheet.title!},;"
<a href="http://twitter.com/home?status=${options.blog_url!}/archives/${post.url!} ,${options.blog_title!},${post.title!},;"
class="fa fa-twitter"></a>
</div>
</div>
<div id="comment_widget">
<#include "module/comment.ftl">
<@comment id="${sheet.id!}" type="sheet" />
</div>
</div>
</div>