NoticeController.java 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package nju.seec.helper.controller;
  2. import nju.seec.helper.aspect.auth.Auth;
  3. import nju.seec.helper.controller.response.PageResponse;
  4. import nju.seec.helper.dto.LoginUser;
  5. import nju.seec.helper.dto.NoticeDTO;
  6. import nju.seec.helper.dto.groups.Create;
  7. import nju.seec.helper.dto.groups.Modify;
  8. import nju.seec.helper.service.NoticeService;
  9. import nju.seec.helper.util.enums.UserType;
  10. import nju.seec.helper.vo.NoticeVO;
  11. import org.springframework.data.domain.Pageable;
  12. import org.springframework.data.web.PageableDefault;
  13. import org.springframework.validation.annotation.Validated;
  14. import org.springframework.web.bind.annotation.*;
  15. /**
  16. * @author cst
  17. */
  18. @RestController
  19. @RequestMapping("/api/notice")
  20. public class NoticeController {
  21. private final NoticeService noticeService;
  22. public NoticeController(NoticeService noticeService) {
  23. this.noticeService = noticeService;
  24. }
  25. @Auth(roles = UserType.TEACHER, message = "发布公告")
  26. @PostMapping
  27. public NoticeVO createNotice(LoginUser user,
  28. @Validated(Create.class) @RequestBody NoticeDTO noticeDTO) {
  29. return noticeService.create(user, noticeDTO);
  30. }
  31. @Auth(roles = UserType.TEACHER, message = "修改公告")
  32. @PutMapping
  33. public NoticeVO modifyNotice(LoginUser user,
  34. @Validated(Modify.class) @RequestBody NoticeDTO noticeDTO) {
  35. return noticeService.modify(user, noticeDTO);
  36. }
  37. @Auth(roles = UserType.TEACHER, message = "删除公告")
  38. @DeleteMapping("/{noticeId}")
  39. public void removeNotice(LoginUser user,
  40. @PathVariable Long noticeId) {
  41. noticeService.deleteNotice(user, noticeId);
  42. }
  43. @Auth(roles = {UserType.TEACHER, UserType.STUDENT}, message = "获取公告")
  44. @GetMapping("/course/{courseId}")
  45. public PageResponse<NoticeVO> getNotices(LoginUser user,
  46. @PathVariable Long courseId,
  47. @RequestParam(defaultValue = "") String key,
  48. @PageableDefault(size = Integer.MAX_VALUE) Pageable pageable) {
  49. return PageResponse.of(noticeService.getNoticesByCourse(user, courseId, key, pageable));
  50. }
  51. }