完善了删除功能
This commit is contained in:
parent
f9272335f2
commit
d027e26f8c
@ -1,99 +1,3 @@
|
||||
//package org.cmh.backend.CourseManagement.service;
|
||||
//
|
||||
//import org.cmh.backend.CourseManagement.model.Course;
|
||||
//import org.cmh.backend.CourseManagement.repository.CourseRepository;
|
||||
//import org.springframework.beans.factory.annotation.Autowired;
|
||||
//import org.springframework.stereotype.Service;
|
||||
//import org.springframework.web.multipart.MultipartFile;
|
||||
//
|
||||
//import java.io.IOException;
|
||||
//import java.nio.file.Files;
|
||||
//import java.nio.file.Path;
|
||||
//import java.nio.file.Paths;
|
||||
//import java.util.List;
|
||||
//import java.util.Optional;
|
||||
//
|
||||
//@Service
|
||||
//public class CourseService {
|
||||
//
|
||||
// @Autowired
|
||||
// private CourseRepository courseRepository;
|
||||
//
|
||||
// public Course createCourse(String name, String description, String author, String sortOrder, MultipartFile coverImage, MultipartFile video) {
|
||||
// Optional<Course> existingCourse = courseRepository.findByName(name);
|
||||
// if (existingCourse.isPresent()) {
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// Course course = new Course();
|
||||
// course.setName(name);
|
||||
// course.setDescription(description);
|
||||
// course.setAuthor(author);
|
||||
// course.setSortOrder(sortOrder);
|
||||
//
|
||||
// try {
|
||||
// if (coverImage != null && !coverImage.isEmpty()) {
|
||||
// String coverImagePath = saveFile(coverImage);
|
||||
// course.setCoverImagePath(coverImagePath);
|
||||
// }
|
||||
// if (video != null && !video.isEmpty()) {
|
||||
// String videoPath = saveFile(video);
|
||||
// course.setVideoPath(videoPath);
|
||||
// }
|
||||
// } catch (IOException e) {
|
||||
// e.printStackTrace();
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// return courseRepository.save(course);
|
||||
// }
|
||||
//
|
||||
// public Course updateCourse(Long id, String name, String description, String author, String sortOrder, MultipartFile coverImage, MultipartFile video) {
|
||||
// return courseRepository.findById(id)
|
||||
// .map(course -> {
|
||||
// course.setName(name);
|
||||
// course.setDescription(description);
|
||||
// course.setAuthor(author);
|
||||
// course.setSortOrder(sortOrder);
|
||||
//
|
||||
// try {
|
||||
// if (coverImage != null && !coverImage.isEmpty()) {
|
||||
// String coverImagePath = saveFile(coverImage);
|
||||
// course.setCoverImagePath(coverImagePath);
|
||||
// }
|
||||
// if (video != null && !video.isEmpty()) {
|
||||
// String videoPath = saveFile(video);
|
||||
// course.setVideoPath(videoPath);
|
||||
// }
|
||||
// } catch (IOException e) {
|
||||
// e.printStackTrace();
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// return courseRepository.save(course);
|
||||
// }).orElse(null);
|
||||
// }
|
||||
//
|
||||
// private String saveFile(MultipartFile file) throws IOException {
|
||||
// String filename = System.currentTimeMillis() + "_" + file.getOriginalFilename();
|
||||
// Path filePath = Paths.get("uploads", filename);
|
||||
// Files.createDirectories(filePath.getParent());
|
||||
// Files.write(filePath, file.getBytes());
|
||||
// return filePath.toString();
|
||||
// }
|
||||
//
|
||||
// public boolean deleteCourse(Long id) {
|
||||
// return courseRepository.findById(id)
|
||||
// .map(course -> {
|
||||
// courseRepository.delete(course);
|
||||
// return true;
|
||||
// }).orElse(false);
|
||||
// }
|
||||
//
|
||||
// public List<Course> getAllCourses() {
|
||||
// return courseRepository.findAll();
|
||||
// }
|
||||
//}
|
||||
package org.cmh.backend.CourseManagement.service;
|
||||
|
||||
import jakarta.persistence.EntityNotFoundException;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user