This commit is contained in:
ronger 2021-04-20 10:16:26 +08:00
parent a9be5d50fe
commit 00a82ff67e
3 changed files with 13 additions and 3 deletions

View File

@ -67,7 +67,7 @@ public interface ArticleService extends Service<Article> {
* @param id * @param id
* @return * @return
* */ * */
Map delete(Integer id); Map delete(Integer id) throws BaseApiException;
/** /**
* 增量文章浏览数 * 增量文章浏览数

View File

@ -249,8 +249,18 @@ public class ArticleServiceImpl extends AbstractService<Article> implements Arti
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public Map delete(Integer id) { public Map delete(Integer id) throws BaseApiException {
Map<String, String> map = new HashMap(1); Map<String, String> map = new HashMap(1);
// 鉴权
User user = UserUtils.getCurrentUserByToken();
Integer roleWeights = userService.findRoleWeightsByUser(user.getIdUser());
if (roleWeights > 2) {
Article article = articleMapper.selectByPrimaryKey(id);
if (!user.getIdUser().equals(article.getArticleAuthorId())) {
map.put("message", "非法访问!");
return map;
}
}
Integer result; Integer result;
// 判断是否有评论 // 判断是否有评论
boolean isHavComment = articleMapper.existsCommentWithPrimaryKey(id); boolean isHavComment = articleMapper.existsCommentWithPrimaryKey(id);

View File

@ -61,7 +61,7 @@ public class ArticleController {
} }
@DeleteMapping("/delete/{id}") @DeleteMapping("/delete/{id}")
public GlobalResult delete(@PathVariable Integer id) { public GlobalResult delete(@PathVariable Integer id) throws BaseApiException {
Map map = articleService.delete(id); Map map = articleService.delete(id);
return GlobalResultGenerator.genSuccessResult(map); return GlobalResultGenerator.genSuccessResult(map);
} }