|
@@ -4,12 +4,17 @@ import cn.minbb.edu.model.Course;
|
|
|
import cn.minbb.edu.model.User;
|
|
|
import cn.minbb.edu.service.CourseService;
|
|
|
import cn.minbb.edu.service.UserService;
|
|
|
+import cn.minbb.edu.storage.FileService;
|
|
|
+import cn.minbb.edu.storage.StorageProperties;
|
|
|
+import cn.minbb.edu.system.Const;
|
|
|
import cn.minbb.edu.system.UserSession;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
import org.springframework.web.servlet.ModelAndView;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
@@ -21,11 +26,13 @@ public class CourseController {
|
|
|
|
|
|
private UserService userService;
|
|
|
private CourseService courseService;
|
|
|
+ private FileService fileService;
|
|
|
|
|
|
@Autowired
|
|
|
- public CourseController(UserService userService, CourseService courseService) {
|
|
|
+ public CourseController(UserService userService, CourseService courseService, FileService fileService) {
|
|
|
this.userService = userService;
|
|
|
this.courseService = courseService;
|
|
|
+ this.fileService = fileService;
|
|
|
}
|
|
|
|
|
|
@GetMapping(value = "create")
|
|
@@ -34,8 +41,42 @@ public class CourseController {
|
|
|
return modelAndView;
|
|
|
}
|
|
|
|
|
|
+ @PostMapping(value = "create")
|
|
|
+ public ModelAndView courseCreate(
|
|
|
+ @RequestParam("name") String name,
|
|
|
+ @RequestParam("introduction") String introduction,
|
|
|
+ @RequestParam("remark") String remark,
|
|
|
+ @RequestParam("cover") MultipartFile cover,
|
|
|
+ @RequestParam("video") MultipartFile video,
|
|
|
+ ModelAndView modelAndView, HttpServletRequest request) {
|
|
|
+ User user = UserSession.getUserAuthentication();
|
|
|
+ if (null != user) {
|
|
|
+ int userId = user.getId();
|
|
|
+ String coverFilename = cover.getOriginalFilename();
|
|
|
+ String videoFilename = video.getOriginalFilename();
|
|
|
+ String filenamePrefix = userId + "-" + System.currentTimeMillis();
|
|
|
+ if (null != coverFilename && null != videoFilename) {
|
|
|
+ String coverFilenameStore = filenamePrefix + coverFilename.substring(coverFilename.lastIndexOf("."));
|
|
|
+ String videoFilenameStore = filenamePrefix + videoFilename.substring(videoFilename.lastIndexOf("."));
|
|
|
+ fileService.storeToFolder(cover, coverFilenameStore, StorageProperties.Folder.IMAGES);
|
|
|
+ fileService.storeToFolder(video, videoFilenameStore, StorageProperties.Folder.VIDEOS);
|
|
|
+ Course course = new Course();
|
|
|
+ course.setName(name);
|
|
|
+ course.setIntroduction(introduction);
|
|
|
+ course.setRemark(remark);
|
|
|
+ course.setCover(coverFilenameStore);
|
|
|
+ course.setVideo(videoFilenameStore);
|
|
|
+ course.setTeacherId(userId);
|
|
|
+ courseService.save(course);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ modelAndView.setViewName("redirect:/course/center");
|
|
|
+ return modelAndView;
|
|
|
+ }
|
|
|
+
|
|
|
@GetMapping(value = "square")
|
|
|
public ModelAndView courseSquarePage(ModelAndView modelAndView, HttpServletRequest request) {
|
|
|
+ modelAndView.addObject("STORAGE_HOST", Const.STORAGE_HOST);
|
|
|
modelAndView.setViewName("course-square");
|
|
|
return modelAndView;
|
|
|
}
|
|
@@ -46,6 +87,7 @@ public class CourseController {
|
|
|
if (null != user) {
|
|
|
List<Course> courseList = courseService.findAllByUserId(user.getId());
|
|
|
modelAndView.addObject("courseList", courseList);
|
|
|
+ modelAndView.addObject("STORAGE_HOST", Const.STORAGE_HOST);
|
|
|
modelAndView.setViewName("course-center");
|
|
|
} else {
|
|
|
modelAndView.setViewName("redirect:/");
|
|
@@ -60,6 +102,7 @@ public class CourseController {
|
|
|
if (null != id) {
|
|
|
Course course = courseService.findOneById(id);
|
|
|
modelAndView.addObject("course", course);
|
|
|
+ modelAndView.addObject("STORAGE_HOST", Const.STORAGE_HOST);
|
|
|
}
|
|
|
modelAndView.setViewName("course-player");
|
|
|
return modelAndView;
|