优化event的时间属性 && 新增线上课章节和课时的排序编辑apic

This commit is contained in:
none
2023-03-20 10:55:14 +08:00
parent 00e4e66271
commit 337e600432
26 changed files with 139 additions and 41 deletions

View File

@@ -11,7 +11,9 @@ import xyz.playedu.api.event.CourseChapterDestroyEvent;
import xyz.playedu.api.exception.NotFoundException;
import xyz.playedu.api.middleware.BackendPermissionMiddleware;
import xyz.playedu.api.request.backend.CourseChapterRequest;
import xyz.playedu.api.request.backend.CourseChapterSortRequest;
import xyz.playedu.api.service.CourseChapterService;
import xyz.playedu.api.service.CourseHourService;
import xyz.playedu.api.types.JsonResponse;
import java.util.Date;
@@ -27,6 +29,9 @@ public class CourseChapterController {
@Autowired
private CourseChapterService chapterService;
@Autowired
private CourseHourService hourService;
@Autowired
private ApplicationContext ctx;
@@ -56,8 +61,17 @@ public class CourseChapterController {
@DeleteMapping("/{id}")
public JsonResponse destroy(@PathVariable(name = "courseId") Integer courseId, @PathVariable(name = "id") Integer id) throws NotFoundException {
CourseChapter chapter = chapterService.findOrFail(id, courseId);
if (hourService.getCountByChapterId(chapter.getId()) > 0) {
return JsonResponse.error("当前章节下面存在课时无法删除");
}
chapterService.removeById(chapter.getId());
ctx.publishEvent(new CourseChapterDestroyEvent(this, PlayEduBContext.getAdminUserID(), chapter.getCourseId(), chapter.getId(), new Date()));
ctx.publishEvent(new CourseChapterDestroyEvent(this, PlayEduBContext.getAdminUserID(), chapter.getCourseId(), chapter.getId()));
return JsonResponse.success();
}
@PutMapping("/update/sort")
public JsonResponse updateSort(@PathVariable(name = "courseId") Integer courseId, @RequestBody @Validated CourseChapterSortRequest req) {
chapterService.updateSort(req.getIds(), courseId);
return JsonResponse.success();
}
}

View File

@@ -185,7 +185,7 @@ public class CourseController {
@DeleteMapping("/{id}")
public JsonResponse destroy(@PathVariable(name = "id") Integer id) {
courseService.removeById(id);
ctx.publishEvent(new CourseDestroyEvent(this, PlayEduBContext.getAdminUserID(), id, new Date()));
ctx.publishEvent(new CourseDestroyEvent(this, PlayEduBContext.getAdminUserID(), id));
return JsonResponse.success();
}

View File

@@ -14,6 +14,7 @@ import xyz.playedu.api.event.CourseHourDestroyEvent;
import xyz.playedu.api.exception.NotFoundException;
import xyz.playedu.api.middleware.BackendPermissionMiddleware;
import xyz.playedu.api.request.backend.CourseHourRequest;
import xyz.playedu.api.request.backend.CourseHourSortRequest;
import xyz.playedu.api.service.CourseChapterService;
import xyz.playedu.api.service.CourseHourService;
import xyz.playedu.api.types.JsonResponse;
@@ -74,7 +75,7 @@ public class CourseHourController {
chapterService.findOrFail(chapterId, courseId);
CourseHour courseHour = hourService.create(courseId, chapterId, req.getSort(), req.getTitle(), type, req.getRid(), req.getDuration());
ctx.publishEvent(new CourseHourCreatedEvent(this, PlayEduBContext.getAdminUserID(), courseHour.getCourseId(), courseHour.getChapterId(), courseHour.getId(), new Date()));
ctx.publishEvent(new CourseHourCreatedEvent(this, PlayEduBContext.getAdminUserID(), courseHour.getCourseId(), courseHour.getChapterId(), courseHour.getId()));
return JsonResponse.success();
}
@@ -102,7 +103,13 @@ public class CourseHourController {
public JsonResponse destroy(@PathVariable(name = "courseId") Integer courseId, @PathVariable(name = "id") Integer id) throws NotFoundException {
CourseHour courseHour = hourService.findOrFail(id, courseId);
hourService.removeById(courseHour.getId());
ctx.publishEvent(new CourseHourDestroyEvent(this, PlayEduBContext.getAdminUserID(), courseHour.getCourseId(), courseHour.getChapterId(), courseHour.getId(), new Date()));
ctx.publishEvent(new CourseHourDestroyEvent(this, PlayEduBContext.getAdminUserID(), courseHour.getCourseId(), courseHour.getChapterId(), courseHour.getId()));
return JsonResponse.success();
}
@PutMapping("/update/sort")
public JsonResponse updateSort(@PathVariable(name = "courseId") Integer courseId, @RequestBody @Validated CourseHourSortRequest req) {
hourService.updateSort(req.getIds(), courseId);
return JsonResponse.success();
}

View File

@@ -119,7 +119,7 @@ public class DepartmentController {
public JsonResponse destroy(@PathVariable Integer id) throws NotFoundException {
Department department = departmentService.findOrFail(id);
departmentService.deleteById(department.getId());
ctx.publishEvent(new DepartmentDestroyEvent(this, PlayEduBContext.getAdminUserID(), department.getId(), new Date()));
ctx.publishEvent(new DepartmentDestroyEvent(this, PlayEduBContext.getAdminUserID(), department.getId()));
return JsonResponse.success();
}

View File

@@ -62,7 +62,7 @@ public class LoginController {
data.put("token", token.getToken());
data.put("expire", token.getExpire());
ctx.publishEvent(new AdminUserLoginEvent(this, adminUser.getId(), new Date(), token.getToken(), IpUtil.getIpAddress(), adminUser.getLoginTimes()));
ctx.publishEvent(new AdminUserLoginEvent(this, adminUser.getId(), token.getToken(), IpUtil.getIpAddress(), adminUser.getLoginTimes()));
return JsonResponse.data(data);
}

View File

@@ -124,7 +124,7 @@ public class ResourceCategoryController {
public JsonResponse destroy(@PathVariable Integer id) throws NotFoundException {
ResourceCategory category = categoryService.findOrFail(id);
categoryService.deleteById(category.getId());
ctx.publishEvent(new ResourceCategoryDestroyEvent(this, PlayEduBContext.getAdminUserID(), category.getId(), new Date()));
ctx.publishEvent(new ResourceCategoryDestroyEvent(this, PlayEduBContext.getAdminUserID(), category.getId()));
return JsonResponse.success();
}

View File

@@ -143,7 +143,7 @@ public class UserController {
public JsonResponse destroy(@PathVariable(name = "id") Integer id) throws NotFoundException {
User user = userService.findOrFail(id);
userService.removeById(user.getId());
context.publishEvent(new UserDestroyEvent(this, user.getId(), new Date()));
context.publishEvent(new UserDestroyEvent(this, user.getId()));
return JsonResponse.success();
}