1. 文章管理接口 2. 评论管理接口

This commit is contained in:
ronger 2021-06-28 08:06:37 +08:00
parent ca05c30630
commit a7e0f7feee
7 changed files with 73 additions and 0 deletions

View File

@ -1,5 +1,6 @@
package com.rymcu.forest.dto;
import com.alibaba.fastjson.annotation.JSONField;
import lombok.Data;
import java.util.Date;
@ -44,6 +45,7 @@ public class ArticleDTO {
/** 文章状态 */
private String articleStatus;
/** 更新时间 */
@JSONField(format = "yyyy-MM-dd HH:mm:ss")
private Date updatedTime;
private Author articleAuthor;

View File

@ -1,5 +1,6 @@
package com.rymcu.forest.dto;
import com.alibaba.fastjson.annotation.JSONField;
import lombok.Data;
import java.util.Date;
@ -35,6 +36,7 @@ public class CommentDTO {
/** 0所有人可见1仅楼主和自己可见 */
private String commentVisible;
/** 创建时间 */
@JSONField(format = "yyyy-MM-dd HH:mm:ss")
private Date createdTime;
private Author commenter;

View File

@ -40,4 +40,10 @@ public interface CommentMapper extends Mapper<Comment> {
* @return
*/
Integer updateCommentSharpUrl(@Param("idComment") Integer idComment, @Param("commentSharpUrl") String commentSharpUrl);
/**
* 获取评论列表数据
* @return
*/
List<CommentDTO> selectComments();
}

View File

@ -13,7 +13,24 @@ import java.util.Map;
*/
public interface CommentService extends Service<Comment> {
/**
* 获取文章评论数据
* @param idArticle
* @return
*/
List<CommentDTO> getArticleComments(Integer idArticle);
/**
* 评论
* @param comment
* @param request
* @return
*/
Map postComment(Comment comment, HttpServletRequest request);
/**
* 获取评论列表数据
* @return
*/
List<CommentDTO> findComments();
}

View File

@ -36,6 +36,10 @@ public class CommentServiceImpl extends AbstractService<Comment> implements Comm
@Override
public List<CommentDTO> getArticleComments(Integer idArticle) {
List<CommentDTO> commentDTOList = commentMapper.selectArticleComments(idArticle);
return genComments(commentDTOList);
}
private List<CommentDTO> genComments(List<CommentDTO> commentDTOList) {
commentDTOList.forEach(commentDTO -> {
commentDTO.setTimeAgo(Utils.getTimeAgo(commentDTO.getCreatedTime()));
if (commentDTO.getCommentAuthorId() != null) {
@ -113,4 +117,10 @@ public class CommentServiceImpl extends AbstractService<Comment> implements Comm
return map;
}
@Override
public List<CommentDTO> findComments() {
List<CommentDTO> commentDTOList = commentMapper.selectComments();
return genComments(commentDTOList);
}
}

View File

@ -4,6 +4,9 @@ import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.rymcu.forest.core.result.GlobalResult;
import com.rymcu.forest.core.result.GlobalResultGenerator;
import com.rymcu.forest.dto.ArticleDTO;
import com.rymcu.forest.dto.ArticleSearchDTO;
import com.rymcu.forest.dto.CommentDTO;
import com.rymcu.forest.dto.UserSearchDTO;
import com.rymcu.forest.dto.admin.TopicTagDTO;
import com.rymcu.forest.dto.admin.UserRoleDTO;
@ -36,6 +39,10 @@ public class AdminController {
private TagService tagService;
@Resource
private SpecialDayService specialDayService;
@Resource
private ArticleService articleService;
@Resource
private CommentService commentService;
@GetMapping("/users")
public GlobalResult<Map<String, Object>> users(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "10") Integer rows, UserSearchDTO searchDTO){
@ -219,4 +226,30 @@ public class AdminController {
return GlobalResultGenerator.genSuccessResult(map);
}
@GetMapping("/articles")
public GlobalResult<Map> articles(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "10") Integer rows, ArticleSearchDTO articleSearchDTO) {
PageHelper.startPage(page, rows);
List<ArticleDTO> list = articleService.findArticles(articleSearchDTO);
PageInfo<ArticleDTO> pageInfo = new PageInfo<>(list);
Map<String, Object> map = new HashMap<>(2);
map.put("articles", pageInfo.getList());
Map pagination = Utils.getPagination(pageInfo);
map.put("pagination", pagination);
return GlobalResultGenerator.genSuccessResult(map);
}
@GetMapping("/comments")
public GlobalResult<Map> comments(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "10") Integer rows) {
PageHelper.startPage(page, rows);
List<CommentDTO> list = commentService.findComments();
PageInfo<CommentDTO> pageInfo = new PageInfo<>(list);
Map<String, Object> map = new HashMap<>(2);
map.put("comments", pageInfo.getList());
Map pagination = Utils.getPagination(pageInfo);
map.put("pagination", pagination);
return GlobalResultGenerator.genSuccessResult(map);
}
}

View File

@ -47,4 +47,7 @@
<select id="selectCommentOriginalAuthor" resultMap="AuthorResultMap">
select vu.id,vu.nickname,vu.avatar_url,vu.account from forest_comment vc left join forest_user vu on vu.id = vc.comment_author_id where vc.id = #{commentOriginalCommentId}
</select>
<select id="selectComments" resultMap="DTOResultMap">
select * from forest_comment order by created_time desc
</select>
</mapper>