diff --git a/src/main/java/cn/teammodel/controller/frontend/NewsController.java b/src/main/java/cn/teammodel/controller/frontend/NewsController.java index 6061ffa..cc03a31 100644 --- a/src/main/java/cn/teammodel/controller/frontend/NewsController.java +++ b/src/main/java/cn/teammodel/controller/frontend/NewsController.java @@ -2,8 +2,6 @@ package cn.teammodel.controller.frontend; import cn.teammodel.common.IdRequest; import cn.teammodel.common.R; -import cn.teammodel.model.dto.ai.CreateNewsDto; -import cn.teammodel.model.dto.ai.UpdateNewsDto; import cn.teammodel.model.dto.news.CreateNewsDto; import cn.teammodel.model.dto.news.UpdateNewsDto; import cn.teammodel.model.entity.news.News; @@ -52,6 +50,6 @@ public class NewsController { @ApiOperation("删除聊天应用") public R deleteNews(@RequestBody @Valid IdRequest idRequest) { newsService.deleteNews(idRequest); - return R.success("删除应用成功"); + return R.success("删除新闻成功"); } } diff --git a/src/main/java/cn/teammodel/service/impl/NewsServiceImpl.java b/src/main/java/cn/teammodel/service/impl/NewsServiceImpl.java index a179266..798664d 100644 --- a/src/main/java/cn/teammodel/service/impl/NewsServiceImpl.java +++ b/src/main/java/cn/teammodel/service/impl/NewsServiceImpl.java @@ -63,7 +63,7 @@ public class NewsServiceImpl implements NewsService { if (ObjectUtils.isEmpty(news)) { throw new ServiceException(ErrorCode.PARAMS_ERROR.getCode(), "该新闻不存在"); } - if (!userId.equals(news.getCreatorId())) { + if (!userId.equals(news.getCreatorId()) && !user.getRoles().contains("admin")) { throw new ServiceException(ErrorCode.NO_AUTH_ERROR.getCode(), "您没有权限修改该新闻"); } BeanUtils.copyProperties(updateNewsDto, news); @@ -72,6 +72,15 @@ public class NewsServiceImpl implements NewsService { @Override public void deleteNews(IdRequest idRequest) { - + String newsId = idRequest.getId(); + User user = SecurityUtil.getLoginUser(); + String userId = user.getId(); + String schoolId = user.getSchoolId(); + News news = newsRepository.findNewsByIdAndCode(newsId, String.format(PK.NEWS, schoolId)); + if (userId.equals(news.getCreatorId()) && user.getRoles().contains("admin")) { + newsRepository.deleteById(newsId, PK.buildOf(PK.NEWS, schoolId)); + } else { + throw new ServiceException(ErrorCode.NO_AUTH_ERROR.getCode(), "您没有权限删除该新闻"); + } } }