ronger 2021-04-20 14:31:28 +08:00 committed by GitHub
commit cb85e139d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 3 deletions

View File

@ -67,7 +67,7 @@ public interface ArticleService extends Service<Article> {
* @param id
* @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
@Transactional(rollbackFor = Exception.class)
public Map delete(Integer id) {
public Map delete(Integer id) throws BaseApiException {
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;
// 判断是否有评论
boolean isHavComment = articleMapper.existsCommentWithPrimaryKey(id);

View File

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