package nju.seec.helper.controller; import nju.seec.helper.aspect.auth.Auth; import nju.seec.helper.controller.response.PageResponse; import nju.seec.helper.dto.LoginUser; import nju.seec.helper.dto.NoticeDTO; import nju.seec.helper.dto.groups.Create; import nju.seec.helper.dto.groups.Modify; import nju.seec.helper.service.NoticeService; import nju.seec.helper.util.enums.UserType; import nju.seec.helper.vo.NoticeVO; import org.springframework.data.domain.Pageable; import org.springframework.data.web.PageableDefault; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; /** * @author cst */ @RestController @RequestMapping("/api/notice") public class NoticeController { private final NoticeService noticeService; public NoticeController(NoticeService noticeService) { this.noticeService = noticeService; } @Auth(roles = UserType.TEACHER, message = "发布公告") @PostMapping public NoticeVO createNotice(LoginUser user, @Validated(Create.class) @RequestBody NoticeDTO noticeDTO) { return noticeService.create(user, noticeDTO); } @Auth(roles = UserType.TEACHER, message = "修改公告") @PutMapping public NoticeVO modifyNotice(LoginUser user, @Validated(Modify.class) @RequestBody NoticeDTO noticeDTO) { return noticeService.modify(user, noticeDTO); } @Auth(roles = UserType.TEACHER, message = "删除公告") @DeleteMapping("/{noticeId}") public void removeNotice(LoginUser user, @PathVariable Long noticeId) { noticeService.deleteNotice(user, noticeId); } @Auth(roles = {UserType.TEACHER, UserType.STUDENT}, message = "获取公告") @GetMapping("/course/{courseId}") public PageResponse getNotices(LoginUser user, @PathVariable Long courseId, @RequestParam(defaultValue = "") String key, @PageableDefault(size = Integer.MAX_VALUE) Pageable pageable) { return PageResponse.of(noticeService.getNoticesByCourse(user, courseId, key, pageable)); } }