课程分类代码优化

This commit is contained in:
none
2023-02-25 10:35:24 +08:00
parent 75fa2abb32
commit 138e1f5b98
4 changed files with 34 additions and 24 deletions

View File

@@ -34,9 +34,6 @@ public class CourseCategoryController {
@Autowired
private ApplicationContext ctx;
@Autowired
private CourseCategoryBus courseCategoryBus;
@GetMapping("/index")
public JsonResponse index() {
Map<Integer, List<CourseCategory>> categories = categoryService.all().stream().collect(Collectors.groupingBy(CourseCategory::getParentId));
@@ -56,22 +53,8 @@ public class CourseCategoryController {
@BackendPermissionMiddleware(slug = BPermissionConstant.COURSE_CATEGORY)
@PostMapping("/create")
public JsonResponse store(@RequestBody @Validated CourseCategoryRequest request) throws NotFoundException {
String parentChain = "";
if (request.getParentId() != 0) {
parentChain = courseCategoryBus.compParentChain(request.getParentId());
}
CourseCategory category = new CourseCategory();
category.setName(request.getName());
category.setParentId(request.getParentId());
category.setParentChain(parentChain);
category.setSort(request.getSort());
category.setCreatedAt(new Date());
category.setUpdatedAt(new Date());
categoryService.save(category);
public JsonResponse store(@RequestBody @Validated CourseCategoryRequest req) throws NotFoundException {
categoryService.create(req.getName(), req.getParentId(), req.getSort());
return JsonResponse.success();
}
@@ -84,9 +67,9 @@ public class CourseCategoryController {
@BackendPermissionMiddleware(slug = BPermissionConstant.COURSE_CATEGORY)
@PutMapping("/{id}")
public JsonResponse update(@PathVariable Integer id, @RequestBody CourseCategoryRequest request) throws NotFoundException {
public JsonResponse update(@PathVariable Integer id, @RequestBody CourseCategoryRequest req) throws NotFoundException {
CourseCategory category = categoryService.findOrFail(id);
categoryService.update(category, request.getName(), request.getParentId(), request.getSort());
categoryService.update(category, req.getName(), req.getParentId(), req.getSort());
return JsonResponse.success();
}