mirror of
https://github.com/PlayEdu/PlayEdu
synced 2025-06-22 20:02:42 +08:00
课程列表api && 部门课程api
This commit is contained in:
parent
fd07672154
commit
0ebb278f42
@ -1,14 +1,14 @@
|
|||||||
package xyz.playedu.api.controller.frontend;
|
package xyz.playedu.api.controller.frontend;
|
||||||
|
|
||||||
|
import org.apache.commons.collections4.MapUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
import xyz.playedu.api.domain.Course;
|
import xyz.playedu.api.domain.Course;
|
||||||
import xyz.playedu.api.exception.NotFoundException;
|
import xyz.playedu.api.exception.NotFoundException;
|
||||||
import xyz.playedu.api.service.CourseService;
|
import xyz.playedu.api.service.CourseService;
|
||||||
import xyz.playedu.api.types.JsonResponse;
|
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.HashMap;
|
||||||
|
|
||||||
@ -24,8 +24,16 @@ public class CourseController {
|
|||||||
private CourseService courseService;
|
private CourseService courseService;
|
||||||
|
|
||||||
@GetMapping("/index")
|
@GetMapping("/index")
|
||||||
public JsonResponse index() {
|
public JsonResponse index(@RequestParam HashMap<String, Object> params) {
|
||||||
return JsonResponse.data(null);
|
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}")
|
@GetMapping("/{id}")
|
||||||
@ -38,7 +46,7 @@ public class CourseController {
|
|||||||
HashMap<String, Object> data = new HashMap<>();
|
HashMap<String, Object> data = new HashMap<>();
|
||||||
data.put("course", course);
|
data.put("course", course);
|
||||||
|
|
||||||
return JsonResponse.data(course);
|
return JsonResponse.data(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,18 @@
|
|||||||
package xyz.playedu.api.controller.frontend;
|
package xyz.playedu.api.controller.frontend;
|
||||||
|
|
||||||
|
import org.apache.commons.collections4.MapUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import xyz.playedu.api.domain.Course;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
import xyz.playedu.api.domain.Department;
|
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.service.DepartmentService;
|
||||||
import xyz.playedu.api.types.JsonResponse;
|
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;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -21,9 +26,32 @@ public class DepartmentController {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private DepartmentService departmentService;
|
private DepartmentService departmentService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private CourseService courseService;
|
||||||
|
|
||||||
@GetMapping("/index")
|
@GetMapping("/index")
|
||||||
public JsonResponse index() {
|
public JsonResponse index() {
|
||||||
return JsonResponse.data(departmentService.all().stream().collect(Collectors.groupingBy(Department::getParentId)));
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -40,4 +40,6 @@ public interface CourseService extends IService<Course> {
|
|||||||
void removeCategoryIdRelate(Integer categoryId);
|
void removeCategoryIdRelate(Integer categoryId);
|
||||||
|
|
||||||
List<Course> chunks(List<Integer> ids, List<String> fields);
|
List<Course> chunks(List<Integer> ids, List<String> fields);
|
||||||
|
|
||||||
|
List<Course> chunks(List<Integer> ids);
|
||||||
}
|
}
|
||||||
|
@ -61,6 +61,9 @@ public class CourseServiceImpl extends ServiceImpl<CourseMapper, Course> impleme
|
|||||||
}
|
}
|
||||||
wrapper.in("id", courseIds);
|
wrapper.in("id", courseIds);
|
||||||
}
|
}
|
||||||
|
if (filter.getIsShow() != null) {
|
||||||
|
wrapper.eq("is_show", filter.getIsShow());
|
||||||
|
}
|
||||||
|
|
||||||
String sortFiled = filter.getSortField();
|
String sortFiled = filter.getSortField();
|
||||||
if (sortFiled == null || sortFiled.trim().length() == 0) {
|
if (sortFiled == null || sortFiled.trim().length() == 0) {
|
||||||
@ -198,6 +201,11 @@ public class CourseServiceImpl extends ServiceImpl<CourseMapper, Course> impleme
|
|||||||
public List<Course> chunks(List<Integer> ids, List<String> fields) {
|
public List<Course> chunks(List<Integer> ids, List<String> fields) {
|
||||||
return list(query().getWrapper().in("id", ids).select(fields));
|
return list(query().getWrapper().in("id", ids).select(fields));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Course> chunks(List<Integer> ids) {
|
||||||
|
return list(query().getWrapper().in("id", ids));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -19,4 +19,6 @@ public class CoursePaginateFiler {
|
|||||||
|
|
||||||
private String sortAlgo;
|
private String sortAlgo;
|
||||||
|
|
||||||
|
private Integer isShow;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user