谷粒学院93——课程删除功能
需求如下。
EduCourseController。
@DeleteMapping("deleteCourse/{courseId}")
public R deleteCourse(@PathVariable String courseId) {
Boolean delete = eduCourseService.removeCourse(courseId);
if(delete) {
return R.ok();
} else {
return R.error();
}
}
EduCourseService.
@Autowired
EduCourseDescriptionService eduCourseDescriptionService;
@Autowired
EduChapterService eduChapterService;
@Autowired
EduVideoService eduVideoService;
@Override
public Boolean removeCourse(String courseId) {
// 1.删除课程小节
eduVideoService.deleteVideo(courseId);
// 2.删除课程章节
eduChapterService.deleteChapter(courseId);
// 3.删除课程描述
eduCourseDescriptionService.deleteDescription(courseId);
// 4.删除课程
return baseMapper.deleteById(courseId) > 0;
}
EduVideoServiceImpl
@Override
public void deleteVideo(String courseId) {
QueryWrapper<EduVideo> wrapper = new QueryWrapper<>();
wrapper.eq("course_id", courseId);
baseMapper.delete(wrapper);
}
EduCourseDescriptionServiceImpl
@Override
public void deleteDescription(String courseId) {
baseMapper.deleteById(courseId);
}
deleteChapter之前实现过了,此处不赘述。前端部分请读者自行实现。后端部分使用swagger测试,如下。检验数据库,功能实现。
java全栈日日学 文章被收录于专栏
java全栈每日必学,不要高估自己一年能做的事,不要低估自己十年能做的事