diff --git a/src/main/java/com/teaching/backend/controller/courseResource/CourseResourceController.java b/src/main/java/com/teaching/backend/controller/courseResource/CourseResourceController.java new file mode 100644 index 0000000..af7f8ae --- /dev/null +++ b/src/main/java/com/teaching/backend/controller/courseResource/CourseResourceController.java @@ -0,0 +1,54 @@ +package com.teaching.backend.controller.courseResource; + +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.teaching.backend.common.BaseResponse; +import com.teaching.backend.common.ResultUtils; + +import com.teaching.backend.model.entity.CourseResources; +import com.teaching.backend.service.impl.CourseResourcesServiceImpl; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import java.util.ArrayList; +import java.util.List; + +@RestController +@RequestMapping("/courses") +public class CourseResourceController { + @Autowired + private CourseResourcesServiceImpl courseResourcesService; + @GetMapping("/all") + public BaseResponse> All(){ + System.out.println("学习记录:"+courseResourcesService.list()); + return ResultUtils.success(courseResourcesService.list()); + } + + @GetMapping("/getall") + public BaseResponse getAll(@RequestParam(value = "pagenum", defaultValue = "1") int pagenum, + @RequestParam(value = "pagesize", defaultValue = "10") int pagesize, + String type) { + + List cs = courseResourcesService.getByType(type); + List pageCs = new ArrayList<>(); + //当前页面 + for(int i = (pagenum - 1) * pagesize; i < cs.size() && i < (pagenum) * pagesize; i++){ + pageCs.add(cs.get(i)); + } + long total = cs.size(); // 总记录数 + Page pageInfo = new Page<>(pagenum,pagesize,total); + pageInfo.setRecords(pageCs); + pageInfo.setPages((int)(Math.ceil((double) total / pagesize)));//设置总页数 + return ResultUtils.success(pageInfo); + } + + /** + * 根据id删除 + * @param ids + * @return + */ + @DeleteMapping("/delete") + public BaseResponse deleteRecords(@RequestParam List ids){ + courseResourcesService.removeCourseResources(ids); + return ResultUtils.success("删除成功!!"); + } +}