From c18366836f7acff72d29727c656a4a05e2267356 Mon Sep 17 00:00:00 2001 From: MichaelWin Date: Tue, 28 Oct 2025 13:51:19 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E6=96=B0=E5=A2=9E=E3=80=91=E6=95=99?= =?UTF-8?q?=E7=A8=8B=E6=8E=A5=E5=8F=A3=E6=8E=A7=E5=88=B6=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/controller/CourseController.java | 74 +++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 src/main/java/com/corewing/app/controller/CourseController.java 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()); + } + } + + +}