mirror of
https://github.com/PlayEdu/PlayEdu
synced 2025-12-18 09:44:15 +08:00
后台权限控制
This commit is contained in:
@@ -4,9 +4,11 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import xyz.playedu.api.constant.BPermissionConstant;
|
||||
import xyz.playedu.api.domain.AdminPermission;
|
||||
import xyz.playedu.api.domain.AdminRole;
|
||||
import xyz.playedu.api.domain.AdminRolePermission;
|
||||
import xyz.playedu.api.middleware.BackendPermissionMiddleware;
|
||||
import xyz.playedu.api.request.backend.AdminRoleRequest;
|
||||
import xyz.playedu.api.service.AdminPermissionService;
|
||||
import xyz.playedu.api.service.AdminRolePermissionService;
|
||||
@@ -36,12 +38,14 @@ public class AdminRoleController {
|
||||
@Autowired
|
||||
private AdminRolePermissionService rolePermissionService;
|
||||
|
||||
@BackendPermissionMiddleware(slug = BPermissionConstant.ADMIN_ROLE)
|
||||
@GetMapping("/index")
|
||||
public JsonResponse index() {
|
||||
List<AdminRole> data = roleService.list();
|
||||
return JsonResponse.data(data);
|
||||
}
|
||||
|
||||
@BackendPermissionMiddleware(slug = BPermissionConstant.ADMIN_ROLE)
|
||||
@GetMapping("/create")
|
||||
public JsonResponse create() {
|
||||
List<AdminPermission> permissions = permissionService.listOrderBySortAsc();
|
||||
@@ -50,6 +54,7 @@ public class AdminRoleController {
|
||||
return JsonResponse.data(data);
|
||||
}
|
||||
|
||||
@BackendPermissionMiddleware(slug = BPermissionConstant.ADMIN_ROLE)
|
||||
@PostMapping("/create")
|
||||
@Transactional
|
||||
public JsonResponse store(@RequestBody @Validated AdminRoleRequest request) {
|
||||
@@ -76,6 +81,7 @@ public class AdminRoleController {
|
||||
return JsonResponse.success();
|
||||
}
|
||||
|
||||
@BackendPermissionMiddleware(slug = BPermissionConstant.ADMIN_ROLE)
|
||||
@GetMapping("/{id}")
|
||||
public JsonResponse edit(@PathVariable(name = "id") Integer id) {
|
||||
AdminRole role = roleService.getById(id);
|
||||
@@ -85,6 +91,7 @@ public class AdminRoleController {
|
||||
return JsonResponse.data(role);
|
||||
}
|
||||
|
||||
@BackendPermissionMiddleware(slug = BPermissionConstant.ADMIN_ROLE)
|
||||
@PutMapping("/{id}")
|
||||
@Transactional
|
||||
public JsonResponse update(@PathVariable(name = "id") Integer id, @RequestBody @Validated AdminRoleRequest request) {
|
||||
@@ -116,6 +123,7 @@ public class AdminRoleController {
|
||||
return JsonResponse.success();
|
||||
}
|
||||
|
||||
@BackendPermissionMiddleware(slug = BPermissionConstant.ADMIN_ROLE)
|
||||
@DeleteMapping("/{id}")
|
||||
@Transactional
|
||||
public JsonResponse destroy(@PathVariable(name = "id") Integer id) {
|
||||
|
||||
@@ -5,9 +5,11 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import xyz.playedu.api.constant.BPermissionConstant;
|
||||
import xyz.playedu.api.domain.AdminRole;
|
||||
import xyz.playedu.api.domain.AdminUser;
|
||||
import xyz.playedu.api.domain.AdminUserRole;
|
||||
import xyz.playedu.api.middleware.BackendPermissionMiddleware;
|
||||
import xyz.playedu.api.request.backend.AdminUserRequest;
|
||||
import xyz.playedu.api.service.AdminRoleService;
|
||||
import xyz.playedu.api.service.AdminUserRoleService;
|
||||
@@ -35,6 +37,7 @@ public class AdminUserController {
|
||||
@Autowired
|
||||
private AdminUserRoleService userRoleService;
|
||||
|
||||
@BackendPermissionMiddleware(slug = BPermissionConstant.ADMIN_USER_INDEX)
|
||||
@GetMapping("/index")
|
||||
public JsonResponse Index(@RequestParam(name = "page", defaultValue = "1") Integer page, @RequestParam(name = "size", defaultValue = "10") Integer size) {
|
||||
PaginationResult<AdminUser> result = adminUserService.paginate(page, size, null);
|
||||
@@ -50,6 +53,7 @@ public class AdminUserController {
|
||||
return JsonResponse.data(result);
|
||||
}
|
||||
|
||||
@BackendPermissionMiddleware(slug = BPermissionConstant.ADMIN_USER_STORE)
|
||||
@GetMapping("/create")
|
||||
public JsonResponse create() {
|
||||
List<AdminRole> roles = roleService.list();
|
||||
@@ -59,6 +63,7 @@ public class AdminUserController {
|
||||
|
||||
}
|
||||
|
||||
@BackendPermissionMiddleware(slug = BPermissionConstant.ADMIN_USER_STORE)
|
||||
@PostMapping("/create")
|
||||
@Transactional
|
||||
public JsonResponse store(@RequestBody @Validated AdminUserRequest request) {
|
||||
@@ -100,6 +105,7 @@ public class AdminUserController {
|
||||
return JsonResponse.success();
|
||||
}
|
||||
|
||||
@BackendPermissionMiddleware(slug = BPermissionConstant.ADMIN_USER_UPDATE)
|
||||
@GetMapping("/{id}")
|
||||
public JsonResponse edit(@PathVariable Integer id) {
|
||||
AdminUser adminUser = adminUserService.findById(id);
|
||||
@@ -111,6 +117,7 @@ public class AdminUserController {
|
||||
return JsonResponse.data(adminUser);
|
||||
}
|
||||
|
||||
@BackendPermissionMiddleware(slug = BPermissionConstant.ADMIN_USER_UPDATE)
|
||||
@PutMapping("/{id}")
|
||||
@Transactional
|
||||
public JsonResponse update(@PathVariable Integer id, @RequestBody @Validated AdminUserRequest request) {
|
||||
@@ -159,6 +166,7 @@ public class AdminUserController {
|
||||
return JsonResponse.success();
|
||||
}
|
||||
|
||||
@BackendPermissionMiddleware(slug = BPermissionConstant.ADMIN_USER_DESTROY)
|
||||
@DeleteMapping("/{id}")
|
||||
@Transactional
|
||||
public JsonResponse destroy(@PathVariable Integer id) {
|
||||
|
||||
@@ -5,8 +5,10 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import xyz.playedu.api.bus.DepartmentBus;
|
||||
import xyz.playedu.api.constant.BPermissionConstant;
|
||||
import xyz.playedu.api.domain.Department;
|
||||
import xyz.playedu.api.exception.NotFoundException;
|
||||
import xyz.playedu.api.middleware.BackendPermissionMiddleware;
|
||||
import xyz.playedu.api.request.backend.DepartmentRequest;
|
||||
import xyz.playedu.api.service.DepartmentService;
|
||||
import xyz.playedu.api.types.JsonResponse;
|
||||
@@ -29,6 +31,7 @@ public class DepartmentController {
|
||||
@Autowired
|
||||
private DepartmentBus departmentBus;
|
||||
|
||||
@BackendPermissionMiddleware(slug = BPermissionConstant.DEPARTMENT_INDEX)
|
||||
@GetMapping("/index")
|
||||
public JsonResponse index() {
|
||||
Map<Integer, List<Department>> departments = departmentService.all().stream().collect(Collectors.groupingBy(Department::getParentId));
|
||||
@@ -39,12 +42,14 @@ public class DepartmentController {
|
||||
return JsonResponse.data(data);
|
||||
}
|
||||
|
||||
@BackendPermissionMiddleware(slug = BPermissionConstant.DEPARTMENT_STORE)
|
||||
@GetMapping("/create")
|
||||
public JsonResponse create(@RequestParam(name = "parent_id", defaultValue = "0") Integer parentId) {
|
||||
List<Department> data = departmentService.listByParentId(parentId);
|
||||
return JsonResponse.data(data);
|
||||
}
|
||||
|
||||
@BackendPermissionMiddleware(slug = BPermissionConstant.DEPARTMENT_STORE)
|
||||
@PostMapping("/create")
|
||||
public JsonResponse store(@RequestBody @Validated DepartmentRequest request) throws NotFoundException {
|
||||
String parentChain = "";
|
||||
@@ -65,12 +70,14 @@ public class DepartmentController {
|
||||
return JsonResponse.success();
|
||||
}
|
||||
|
||||
@BackendPermissionMiddleware(slug = BPermissionConstant.DEPARTMENT_UPDATE)
|
||||
@GetMapping("/{id}")
|
||||
public JsonResponse edit(@PathVariable Integer id) throws NotFoundException {
|
||||
Department department = departmentService.findOrFail(id);
|
||||
return JsonResponse.data(department);
|
||||
}
|
||||
|
||||
@BackendPermissionMiddleware(slug = BPermissionConstant.DEPARTMENT_UPDATE)
|
||||
@PutMapping("/{id}")
|
||||
public JsonResponse update(@PathVariable Integer id, @RequestBody DepartmentRequest request) throws NotFoundException {
|
||||
Department department = departmentService.findOrFail(id);
|
||||
@@ -78,6 +85,7 @@ public class DepartmentController {
|
||||
return JsonResponse.success();
|
||||
}
|
||||
|
||||
@BackendPermissionMiddleware(slug = BPermissionConstant.DEPARTMENT_DESTROY)
|
||||
@DeleteMapping("/{id}")
|
||||
public JsonResponse destroy(@PathVariable Integer id) throws NotFoundException {
|
||||
Department department = departmentService.findOrFail(id);
|
||||
|
||||
Reference in New Issue
Block a user