diff --git a/src/main/java/com/corewing/app/controller/CourseController.java b/src/main/java/com/corewing/app/controller/CourseController.java new file mode 100644 index 0000000..ea10563 --- /dev/null +++ b/src/main/java/com/corewing/app/controller/CourseController.java @@ -0,0 +1,74 @@ +package com.corewing.app.controller; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.corewing.app.common.Result; +import com.corewing.app.entity.Course; +import com.corewing.app.entity.CourseCategory; +import com.corewing.app.service.CourseCategoryService; +import com.corewing.app.service.CourseService; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + +/** + * 教程接口 + */ +@RequestMapping("/course") +@RestController +public class CourseController { + + private final CourseService courseService; + private final CourseCategoryService courseCategoryService; + + public CourseController(CourseService courseService, CourseCategoryService courseCategoryService) { + this.courseService = courseService; + this.courseCategoryService = courseCategoryService; + } + + /** + * 分类查询列表 + * + * @param firstStatus 置首状态(选填) + * + */ + @GetMapping("/category") + public Result> category( + @RequestParam(required = false, defaultValue = "0") Integer firstStatus + ) { + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(firstStatus != 0, CourseCategory::getFirstStatus, firstStatus); + List list = courseCategoryService.list(wrapper); + return Result.success(list); + } + + /** + * 分页查询教程列表 + * + * @param current 当前页码 + * @param size 每页数量 + * @param categoryId 分类ID(选填) + * @param courseTitle 教程标题(选填) + * + */ + @GetMapping("/page") + public Result> getPageList( + @RequestParam(defaultValue = "1") Long current, + @RequestParam(defaultValue = "10") Long size, + @RequestParam(required = false, defaultValue = "0") Integer categoryId, + @RequestParam(required = false) String courseTitle) { + try { + Page page = new Page<>(current, size); + IPage pageResult = courseService.pageList(page, categoryId, courseTitle); + return Result.success(pageResult); + } catch (Exception e) { + return Result.error(e.getMessage()); + } + } + + +}