mirror of
https://github.com/PlayEdu/PlayEdu
synced 2025-12-25 12:22:03 +08:00
课程列表api && 部门课程api
This commit is contained in:
@@ -1,14 +1,14 @@
|
||||
package xyz.playedu.api.controller.frontend;
|
||||
|
||||
import org.apache.commons.collections4.MapUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import xyz.playedu.api.domain.Course;
|
||||
import xyz.playedu.api.exception.NotFoundException;
|
||||
import xyz.playedu.api.service.CourseService;
|
||||
import xyz.playedu.api.types.JsonResponse;
|
||||
import xyz.playedu.api.types.paginate.CoursePaginateFiler;
|
||||
import xyz.playedu.api.types.paginate.PaginationResult;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
@@ -24,8 +24,16 @@ public class CourseController {
|
||||
private CourseService courseService;
|
||||
|
||||
@GetMapping("/index")
|
||||
public JsonResponse index() {
|
||||
return JsonResponse.data(null);
|
||||
public JsonResponse index(@RequestParam HashMap<String, Object> params) {
|
||||
Integer page = MapUtils.getInteger(params, "page", 1);
|
||||
Integer size = MapUtils.getInteger(params, "size", 10);
|
||||
|
||||
CoursePaginateFiler filer = new CoursePaginateFiler();
|
||||
filer.setIsShow(1);
|
||||
|
||||
PaginationResult<Course> result = courseService.paginate(page, size, filer);
|
||||
|
||||
return JsonResponse.data(result);
|
||||
}
|
||||
|
||||
@GetMapping("/{id}")
|
||||
@@ -38,7 +46,7 @@ public class CourseController {
|
||||
HashMap<String, Object> data = new HashMap<>();
|
||||
data.put("course", course);
|
||||
|
||||
return JsonResponse.data(course);
|
||||
return JsonResponse.data(data);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,13 +1,18 @@
|
||||
package xyz.playedu.api.controller.frontend;
|
||||
|
||||
import org.apache.commons.collections4.MapUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import xyz.playedu.api.domain.Course;
|
||||
import xyz.playedu.api.domain.Department;
|
||||
import xyz.playedu.api.exception.NotFoundException;
|
||||
import xyz.playedu.api.service.CourseService;
|
||||
import xyz.playedu.api.service.DepartmentService;
|
||||
import xyz.playedu.api.types.JsonResponse;
|
||||
import xyz.playedu.api.types.paginate.CoursePaginateFiler;
|
||||
import xyz.playedu.api.types.paginate.PaginationResult;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@@ -21,9 +26,32 @@ public class DepartmentController {
|
||||
@Autowired
|
||||
private DepartmentService departmentService;
|
||||
|
||||
@Autowired
|
||||
private CourseService courseService;
|
||||
|
||||
@GetMapping("/index")
|
||||
public JsonResponse index() {
|
||||
return JsonResponse.data(departmentService.all().stream().collect(Collectors.groupingBy(Department::getParentId)));
|
||||
}
|
||||
|
||||
@GetMapping("/{id}/courses")
|
||||
public JsonResponse courses(@PathVariable(name = "id") Integer id, @RequestParam HashMap<String, Object> params) throws NotFoundException {
|
||||
Integer page = MapUtils.getInteger(params, "page", 1);
|
||||
Integer size = MapUtils.getInteger(params, "size", 10);
|
||||
|
||||
Department department = departmentService.findOrFail(id);
|
||||
|
||||
CoursePaginateFiler filer = new CoursePaginateFiler();
|
||||
filer.setIsShow(1);
|
||||
filer.setDepIds(department.getId() + "");
|
||||
|
||||
PaginationResult<Course> result = courseService.paginate(page, size, filer);
|
||||
|
||||
HashMap<String, Object> data = new HashMap<>();
|
||||
data.put("data", result.getData());
|
||||
data.put("total", result.getTotal());
|
||||
|
||||
return JsonResponse.data(data);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user