|
@@ -1,8 +1,10 @@
|
|
|
package cn.minbb.edu.controller.web;
|
|
|
|
|
|
import cn.minbb.edu.model.Course;
|
|
|
+import cn.minbb.edu.model.Subject;
|
|
|
import cn.minbb.edu.model.User;
|
|
|
import cn.minbb.edu.service.CourseService;
|
|
|
+import cn.minbb.edu.service.SubjectService;
|
|
|
import cn.minbb.edu.service.UserService;
|
|
|
import cn.minbb.edu.storage.FileService;
|
|
|
import cn.minbb.edu.storage.StorageProperties;
|
|
@@ -26,17 +28,20 @@ public class CourseController {
|
|
|
|
|
|
private UserService userService;
|
|
|
private CourseService courseService;
|
|
|
+ private SubjectService subjectService;
|
|
|
private FileService fileService;
|
|
|
|
|
|
@Autowired
|
|
|
- public CourseController(UserService userService, CourseService courseService, FileService fileService) {
|
|
|
+ public CourseController(UserService userService, CourseService courseService, SubjectService subjectService, FileService fileService) {
|
|
|
this.userService = userService;
|
|
|
this.courseService = courseService;
|
|
|
+ this.subjectService = subjectService;
|
|
|
this.fileService = fileService;
|
|
|
}
|
|
|
|
|
|
@GetMapping(value = "create")
|
|
|
public ModelAndView courseCreatePage(ModelAndView modelAndView, HttpServletRequest request) {
|
|
|
+ modelAndView.addObject("subjectList", subjectService.findAll());
|
|
|
modelAndView.setViewName("course-create");
|
|
|
return modelAndView;
|
|
|
}
|
|
@@ -44,6 +49,7 @@ public class CourseController {
|
|
|
@PostMapping(value = "create")
|
|
|
public ModelAndView courseCreate(
|
|
|
@RequestParam("name") String name,
|
|
|
+ @RequestParam("subject") String subjectName,
|
|
|
@RequestParam("introduction") String introduction,
|
|
|
@RequestParam("remark") String remark,
|
|
|
@RequestParam("cover") MultipartFile cover,
|
|
@@ -60,6 +66,8 @@ public class CourseController {
|
|
|
String videoFilenameStore = filenamePrefix + videoFilename.substring(videoFilename.lastIndexOf("."));
|
|
|
fileService.storeToFolder(cover, coverFilenameStore, StorageProperties.Folder.IMAGES);
|
|
|
fileService.storeToFolder(video, videoFilenameStore, StorageProperties.Folder.VIDEOS);
|
|
|
+ // 查询学科
|
|
|
+ Subject subject = subjectService.findOneByName(subjectName);
|
|
|
Course course = new Course();
|
|
|
course.setName(name);
|
|
|
course.setIntroduction(introduction);
|
|
@@ -67,6 +75,8 @@ public class CourseController {
|
|
|
course.setCover(Const.STORAGE_HOST + "images/" + coverFilenameStore);
|
|
|
course.setVideo(Const.STORAGE_HOST + "videos/" + videoFilenameStore);
|
|
|
course.setTeacherId(userId);
|
|
|
+ if (null != subject) course.setSubjectId(subject.getId());
|
|
|
+ else course.setSubjectId(0);
|
|
|
courseService.save(course);
|
|
|
}
|
|
|
}
|