|
|
@@ -32,14 +32,14 @@ public class AnnouncementService {
|
|
|
public AnnouncementVO create(AnnouncementVO announcementVO) {
|
|
|
Optional<User> sender = userRepository.findById(announcementVO.getSender().getId());
|
|
|
if (!sender.isPresent()) {
|
|
|
- throw new PortalException(ExceptionType.ERROR, "该公告发布者不存在!");
|
|
|
+ throw new PortalException(ExceptionType.ERROR, "该公告发布者不存在");
|
|
|
}
|
|
|
Optional<Course> course = courseRepository.findById(announcementVO.getCourse().getId());
|
|
|
if (!course.isPresent()) {
|
|
|
- throw new PortalException(ExceptionType.ERROR, "该课程不存在!");
|
|
|
+ throw new PortalException(ExceptionType.ERROR, "该课程不存在");
|
|
|
}
|
|
|
if (!sender.get().getId().equals(course.get().getTeacherId())) {
|
|
|
- throw new PortalException(ExceptionType.ERROR, "公告发布者与课程老师不相同!");
|
|
|
+ throw new PortalException(ExceptionType.ERROR, "公告发布者与课程老师不相同");
|
|
|
}
|
|
|
Announcement announcement = announcementMapper.toAnnouncement(announcementVO);
|
|
|
announcement.setState(ObjectState.NORMAL);
|
|
|
@@ -50,11 +50,11 @@ public class AnnouncementService {
|
|
|
public String delete(Long id, Long userId) {
|
|
|
Optional<Announcement> optionalAnnouncement = announcementRepository.findById(id);
|
|
|
if (!optionalAnnouncement.isPresent()) {
|
|
|
- throw new PortalException(ExceptionType.ERROR, "该公告不存在!");
|
|
|
+ throw new PortalException(ExceptionType.ERROR, "该公告不存在");
|
|
|
}
|
|
|
Announcement announcement = optionalAnnouncement.get();
|
|
|
if (!announcement.getSenderId().equals(userId)) {
|
|
|
- throw new PortalException(ExceptionType.ERROR, "当前角色无法删除该公告!");
|
|
|
+ throw new PortalException(ExceptionType.ERROR, "当前角色无法删除该公告");
|
|
|
}
|
|
|
announcement.setState(ObjectState.DELETED);
|
|
|
announcementRepository.save(announcement);
|
|
|
@@ -64,14 +64,14 @@ public class AnnouncementService {
|
|
|
public AnnouncementVO update(AnnouncementVO announcementVO) {
|
|
|
Optional<Announcement> oldAnnouncement = announcementRepository.findById(announcementVO.getId());
|
|
|
if (!oldAnnouncement.isPresent()) {
|
|
|
- throw new PortalException(ExceptionType.ERROR, "原公告不存在!");
|
|
|
+ throw new PortalException(ExceptionType.ERROR, "原公告不存在");
|
|
|
}
|
|
|
Optional<Course> course = courseRepository.findById(announcementVO.getCourse().getId());
|
|
|
if (!course.isPresent()) {
|
|
|
- throw new PortalException(ExceptionType.ERROR, "该课程不存在!");
|
|
|
+ throw new PortalException(ExceptionType.ERROR, "该课程不存在");
|
|
|
}
|
|
|
if (!announcementVO.getSender().getId().equals(course.get().getTeacherId())) {
|
|
|
- throw new PortalException(ExceptionType.ERROR, "用户无权修改公告!");
|
|
|
+ throw new PortalException(ExceptionType.ERROR, "当前用户无权修改公告");
|
|
|
}
|
|
|
Announcement announcement = announcementMapper.toAnnouncement(announcementVO);
|
|
|
Announcement result = announcementRepository.save(announcement);
|
|
|
@@ -81,7 +81,7 @@ public class AnnouncementService {
|
|
|
public AnnouncementVO getAnnouncementById(Long id) {
|
|
|
Optional<Announcement> announcement = announcementRepository.findById(id);
|
|
|
if (!announcement.isPresent()) {
|
|
|
- throw new PortalException(ExceptionType.ERROR, "该公告不存在!");
|
|
|
+ throw new PortalException(ExceptionType.ERROR, "该公告不存在");
|
|
|
}
|
|
|
return announcementMapper.toAnnouncementVO(announcement.get());
|
|
|
}
|