|
|
@@ -9,12 +9,12 @@ import nju.seec.helper.dto.CourseDTO;
|
|
|
import nju.seec.helper.dto.LoginUser;
|
|
|
import nju.seec.helper.service.CourseService;
|
|
|
import nju.seec.helper.util.enums.UserType;
|
|
|
-import nju.seec.helper.util.exception.HelperException;
|
|
|
import nju.seec.helper.vo.CourseVO;
|
|
|
import org.springframework.data.domain.Pageable;
|
|
|
import org.springframework.data.web.PageableDefault;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
+import javax.validation.Valid;
|
|
|
import java.util.List;
|
|
|
|
|
|
/**
|
|
|
@@ -32,7 +32,7 @@ public class CourseController {
|
|
|
@Auth(roles = UserType.TEACHER, message = "创建课程")
|
|
|
@PostMapping
|
|
|
public ResourceResponse<CourseVO> createCourse(LoginUser user,
|
|
|
- @RequestBody CourseDTO courseDTO) {
|
|
|
+ @Valid @RequestBody CourseDTO courseDTO) {
|
|
|
CourseVO courseVO = courseService.createCourse(user, courseDTO);
|
|
|
return ResourceResponse.of(courseVO);
|
|
|
}
|
|
|
@@ -40,36 +40,33 @@ public class CourseController {
|
|
|
@Auth(roles = UserType.STUDENT, message = "选课")
|
|
|
@PostMapping("/choose")
|
|
|
public EmptyResponse chooseCourse(LoginUser user,
|
|
|
- @RequestBody ChooseDTO chooseDTO) {
|
|
|
+ @Valid @RequestBody ChooseDTO chooseDTO) {
|
|
|
courseService.chooseCourse(user, chooseDTO);
|
|
|
return EmptyResponse.getInstance();
|
|
|
}
|
|
|
|
|
|
- @Auth(roles = {UserType.TEACHER, UserType.STUDENT}, message = "查看课程")
|
|
|
@GetMapping
|
|
|
+ public PageResourceResponse<CourseVO> getCourses(@RequestParam(required = false, defaultValue = "") String key,
|
|
|
+ @PageableDefault(Integer.MAX_VALUE) Pageable pageable) {
|
|
|
+ List<CourseVO> courseVOList = courseService.getCourses(key, pageable);
|
|
|
+ return PageResourceResponse.of(courseVOList, pageable.getPageNumber(), pageable.getPageSize());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Auth(roles = UserType.TEACHER, message = "获取所创课程")
|
|
|
+ @GetMapping("/teacher")
|
|
|
public PageResourceResponse<CourseVO> teacherGetCourses(LoginUser user,
|
|
|
@RequestParam(required = false, defaultValue = "") String key,
|
|
|
@PageableDefault(Integer.MAX_VALUE) Pageable pageable) {
|
|
|
- List<CourseVO> courseVOList;
|
|
|
- switch (user.getType()) {
|
|
|
- case TEACHER:
|
|
|
- courseVOList = courseService.teacherGetCourses(user, key, pageable);
|
|
|
- break;
|
|
|
- case STUDENT:
|
|
|
- courseVOList = courseService.studentGetCourses(user, key, pageable);
|
|
|
- break;
|
|
|
- default:
|
|
|
- throw HelperException.of(HelperException.ExceptionType.FORBIDDEN, "您暂时无法查看课程");
|
|
|
- }
|
|
|
+ List<CourseVO> courseVOList = courseService.teacherGetCourses(user, key, pageable);
|
|
|
return PageResourceResponse.of(courseVOList, pageable.getPageNumber(), pageable.getPageSize());
|
|
|
}
|
|
|
|
|
|
@Auth(roles = UserType.STUDENT, message = "获取所选课程")
|
|
|
- @GetMapping("/choose")
|
|
|
- public PageResourceResponse<CourseVO> studentGetChooseCourses(LoginUser user,
|
|
|
- @RequestParam(required = false, defaultValue = "") String key,
|
|
|
- @PageableDefault(Integer.MAX_VALUE) Pageable pageable) {
|
|
|
- List<CourseVO> courseVOList = courseService.studentGetChooseCourses(user, key, pageable);
|
|
|
+ @GetMapping("/student")
|
|
|
+ public PageResourceResponse<CourseVO> studentGetCourses(LoginUser user,
|
|
|
+ @RequestParam(required = false, defaultValue = "") String key,
|
|
|
+ @PageableDefault(Integer.MAX_VALUE) Pageable pageable) {
|
|
|
+ List<CourseVO> courseVOList = courseService.studentGetCourses(user, key, pageable);
|
|
|
return PageResourceResponse.of(courseVOList, pageable.getPageNumber(), pageable.getPageSize());
|
|
|
}
|
|
|
}
|