🔒 评论接口用户鉴权

This commit is contained in:
ronger 2022-05-11 19:50:28 +08:00
parent ac247f8e68
commit da934ff548
3 changed files with 19 additions and 19 deletions

View File

@ -3,6 +3,7 @@ package com.rymcu.forest.service;
import com.rymcu.forest.core.service.Service;
import com.rymcu.forest.dto.CommentDTO;
import com.rymcu.forest.entity.Comment;
import com.rymcu.forest.web.api.exception.BaseApiException;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
@ -26,7 +27,7 @@ public interface CommentService extends Service<Comment> {
* @param request
* @return
*/
Map postComment(Comment comment, HttpServletRequest request);
Map postComment(Comment comment, HttpServletRequest request) throws BaseApiException;
/**
* 获取评论列表数据

View File

@ -9,10 +9,8 @@ import com.rymcu.forest.entity.Comment;
import com.rymcu.forest.mapper.CommentMapper;
import com.rymcu.forest.service.ArticleService;
import com.rymcu.forest.service.CommentService;
import com.rymcu.forest.util.Html2TextUtil;
import com.rymcu.forest.util.NotificationUtils;
import com.rymcu.forest.util.Utils;
import com.rymcu.forest.util.XssUtils;
import com.rymcu.forest.util.*;
import com.rymcu.forest.web.api.exception.BaseApiException;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -65,7 +63,8 @@ public class CommentServiceImpl extends AbstractService<Comment> implements Comm
@Override
@Transactional(rollbackFor = Exception.class)
public Map postComment(Comment comment, HttpServletRequest request) {
public Map postComment(Comment comment, HttpServletRequest request) throws BaseApiException {
comment.setCommentAuthorId(Objects.requireNonNull(UserUtils.getCurrentUserByToken()).getIdUser());
Map map = new HashMap(1);
if (comment.getCommentArticleId() == null) {
map.put("message", "非法访问,文章主键异常!");

View File

@ -26,7 +26,7 @@ public class CommentController {
private CommentService commentService;
@PostMapping("/post")
public GlobalResult postComment(@RequestBody Comment comment, HttpServletRequest request) throws BaseApiException, UnsupportedEncodingException {
public GlobalResult postComment(@RequestBody Comment comment, HttpServletRequest request) throws BaseApiException {
Map map = commentService.postComment(comment,request);
return GlobalResultGenerator.genSuccessResult(map);
}