【新增】教程接口控制器
This commit is contained in:
@@ -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<List<CourseCategory>> category(
|
||||
@RequestParam(required = false, defaultValue = "0") Integer firstStatus
|
||||
) {
|
||||
LambdaQueryWrapper<CourseCategory> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(firstStatus != 0, CourseCategory::getFirstStatus, firstStatus);
|
||||
List<CourseCategory> list = courseCategoryService.list(wrapper);
|
||||
return Result.success(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询教程列表
|
||||
*
|
||||
* @param current 当前页码
|
||||
* @param size 每页数量
|
||||
* @param categoryId 分类ID(选填)
|
||||
* @param courseTitle 教程标题(选填)
|
||||
*
|
||||
*/
|
||||
@GetMapping("/page")
|
||||
public Result<IPage<Course>> 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<Course> page = new Page<>(current, size);
|
||||
IPage<Course> pageResult = courseService.pageList(page, categoryId, courseTitle);
|
||||
return Result.success(pageResult);
|
||||
} catch (Exception e) {
|
||||
return Result.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user