|
|
@ -63,7 +63,7 @@ public class NewsServiceImpl implements NewsService {
|
|
|
|
if (ObjectUtils.isEmpty(news)) {
|
|
|
|
if (ObjectUtils.isEmpty(news)) {
|
|
|
|
throw new ServiceException(ErrorCode.PARAMS_ERROR.getCode(), "该新闻不存在");
|
|
|
|
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(), "您没有权限修改该新闻");
|
|
|
|
throw new ServiceException(ErrorCode.NO_AUTH_ERROR.getCode(), "您没有权限修改该新闻");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
BeanUtils.copyProperties(updateNewsDto, news);
|
|
|
|
BeanUtils.copyProperties(updateNewsDto, news);
|
|
|
@ -72,6 +72,15 @@ public class NewsServiceImpl implements NewsService {
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void deleteNews(IdRequest idRequest) {
|
|
|
|
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(), "您没有权限删除该新闻");
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|