|
|
@@ -57,24 +57,24 @@ public class CourseService {
|
|
|
public CourseVO createCourse(CourseVO courseVO) {
|
|
|
Integer coderId;
|
|
|
|
|
|
- // 确认授课老师
|
|
|
+ // 确认授课教师
|
|
|
Optional<User> teacher = userRepository.findById(courseVO.getTeacher().getId());
|
|
|
if (!teacher.isPresent()) {
|
|
|
- throw new CustomErrorException("课程老师不存在");
|
|
|
+ throw new CustomErrorException("课程教师不存在");
|
|
|
}
|
|
|
if (!teacher.get().getRole().equals(UserRole.TEACHER) && !teacher.get().getRole().equals(UserRole.ADMIN)) {
|
|
|
- throw new CustomErrorException("仅限管理员和老师创建课程");
|
|
|
+ throw new CustomErrorException("仅限管理员和教师创建课程");
|
|
|
}
|
|
|
|
|
|
- // 创建Coder课程
|
|
|
- JSONObject coderRes = coderService.createService(courseVO);
|
|
|
- if ((int) coderRes.get("err") == 0) {
|
|
|
- JSONObject coderCourse = (JSONObject) coderRes.get("res");
|
|
|
- coderId = (Integer) coderCourse.get("id");
|
|
|
- courseVO.setCoderId(coderId);
|
|
|
- } else {
|
|
|
- throw new CustomErrorException("Coder: " + coderRes.get("msg"));
|
|
|
- }
|
|
|
+ // todo: 创建Coder课程
|
|
|
+// JSONObject coderRes = coderService.createService(courseVO);
|
|
|
+// if ((int) coderRes.get("err") == 0) {
|
|
|
+// JSONObject coderCourse = (JSONObject) coderRes.get("res");
|
|
|
+// coderId = (Integer) coderCourse.get("id");
|
|
|
+// courseVO.setCoderId(coderId);
|
|
|
+// } else {
|
|
|
+// throw new CustomErrorException("Coder: " + coderRes.get("msg"));
|
|
|
+// }
|
|
|
Course course = courseMapper.courseVOToCourse(courseVO);
|
|
|
course.setState(ObjectState.NORMAL);
|
|
|
Course result = courseRepository.save(course);
|
|
|
@@ -138,4 +138,9 @@ public class CourseService {
|
|
|
Optional<Course> optionalCourse = courseRepository.findCourseByCoderId(coderId);
|
|
|
return optionalCourse.map(courseMapper::courseToCourseVO).orElse(null);
|
|
|
}
|
|
|
+
|
|
|
+ public Boolean checkCourseNameUnique(String name){
|
|
|
+ Optional<Course> optionalCourse = courseRepository.findCourseByName(name);
|
|
|
+ return !optionalCourse.isPresent();
|
|
|
+ }
|
|
|
}
|