|
@@ -12,6 +12,9 @@ import cn.seecoder.seecoderportalserver.mapper.AnnouncementMapper;
|
|
|
import cn.seecoder.seecoderportalserver.repository.AnnouncementRepository;
|
|
import cn.seecoder.seecoderportalserver.repository.AnnouncementRepository;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
+
|
|
|
@Service
|
|
@Service
|
|
|
public class AnnouncementService {
|
|
public class AnnouncementService {
|
|
|
private final AnnouncementRepository announcementRepository;
|
|
private final AnnouncementRepository announcementRepository;
|
|
@@ -28,7 +31,7 @@ public class AnnouncementService {
|
|
|
|
|
|
|
|
public AnnouncementVO create(AnnouncementVO announcementVO) {
|
|
public AnnouncementVO create(AnnouncementVO announcementVO) {
|
|
|
UserVO sender = userService.findUserById(announcementVO.getSender().getId());
|
|
UserVO sender = userService.findUserById(announcementVO.getSender().getId());
|
|
|
- CourseVO course = courseService.getCourseById(announcementVO.getCourse().getId());
|
|
|
|
|
|
|
+ CourseVO course = courseService.getCourseById(announcementVO.getId());
|
|
|
if (!sender.getId().equals(course.getTeacher().getId())) {
|
|
if (!sender.getId().equals(course.getTeacher().getId())) {
|
|
|
throw new CustomErrorException("当前用户无权发布公告");
|
|
throw new CustomErrorException("当前用户无权发布公告");
|
|
|
}
|
|
}
|
|
@@ -50,7 +53,7 @@ public class AnnouncementService {
|
|
|
|
|
|
|
|
public AnnouncementVO update(AnnouncementVO announcementVO) {
|
|
public AnnouncementVO update(AnnouncementVO announcementVO) {
|
|
|
this.getAnnouncementById(announcementVO.getId());
|
|
this.getAnnouncementById(announcementVO.getId());
|
|
|
- CourseVO course = courseService.getCourseById(announcementVO.getCourse().getId());
|
|
|
|
|
|
|
+ CourseVO course = courseService.getCourseById(announcementVO.getId());
|
|
|
if (!announcementVO.getSender().getId().equals(course.getTeacher().getId())) {
|
|
if (!announcementVO.getSender().getId().equals(course.getTeacher().getId())) {
|
|
|
throw new PortalException(ExceptionType.ERROR, "当前用户无权修改公告");
|
|
throw new PortalException(ExceptionType.ERROR, "当前用户无权修改公告");
|
|
|
}
|
|
}
|
|
@@ -63,4 +66,12 @@ public class AnnouncementService {
|
|
|
Announcement announcement = announcementRepository.findById(id).orElseThrow(CustomErrorException::announcementNotFound);
|
|
Announcement announcement = announcementRepository.findById(id).orElseThrow(CustomErrorException::announcementNotFound);
|
|
|
return announcementMapper.toAnnouncementVO(announcement);
|
|
return announcementMapper.toAnnouncementVO(announcement);
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ public List<AnnouncementVO> getAnnouncementsByCourseID(Long courseId){
|
|
|
|
|
+ courseService.getCourseById(courseId);
|
|
|
|
|
+ List<Announcement> announcementList = announcementRepository.findAnnouncementsByCourseId(courseId);
|
|
|
|
|
+ return announcementList.stream()
|
|
|
|
|
+ .map(announcementMapper::toAnnouncementVO)
|
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|