diff --git a/console/pom.xml b/console/pom.xml index c7b98a8f..0e6591e8 100644 --- a/console/pom.xml +++ b/console/pom.xml @@ -25,6 +25,11 @@ com.github.dynamic-threadpool discovery + + + com.github.dynamic-threadpool + auth + diff --git a/console/src/main/java/com/github/dynamic/threadpool/console/controller/PermissionController.java b/console/src/main/java/com/github/dynamic/threadpool/console/controller/PermissionController.java new file mode 100644 index 00000000..fe043479 --- /dev/null +++ b/console/src/main/java/com/github/dynamic/threadpool/console/controller/PermissionController.java @@ -0,0 +1,42 @@ +package com.github.dynamic.threadpool.console.controller; + +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.github.dynamic.threadpool.auth.model.biz.permission.PermissionRespDTO; +import com.github.dynamic.threadpool.auth.service.PermissionService; +import com.github.dynamic.threadpool.common.web.base.Result; +import com.github.dynamic.threadpool.common.web.base.Results; +import lombok.AllArgsConstructor; +import org.springframework.web.bind.annotation.*; + +/** + * Permission controller. + * + * @author chen.ma + * @date 2021/10/30 22:08 + */ +@RestController +@AllArgsConstructor +@RequestMapping("/v1/auth/permissions") +public class PermissionController { + + private final PermissionService permissionService; + + @GetMapping("/{pageNo}/{pageSize}") + public Result> listPermission(@PathVariable("pageNo") int pageNo, @PathVariable("pageSize") int pageSize) { + IPage resultPermissionPage = permissionService.listPermission(pageNo, pageSize); + return Results.success(resultPermissionPage); + } + + @PostMapping("/{role}/{resource}/{action}") + public Result addPermission(@PathVariable("role") String role, @PathVariable("resource") String resource, @PathVariable("action") String action) { + permissionService.addPermission(role, resource, action); + return Results.success(); + } + + @DeleteMapping("/{role}/{resource}/{action}") + public Result deleteUser(@PathVariable("role") String role, @PathVariable("resource") String resource, @PathVariable("action") String action) { + permissionService.deletePermission(role, resource, action); + return Results.success(); + } + +} diff --git a/console/src/main/java/com/github/dynamic/threadpool/console/controller/RoleController.java b/console/src/main/java/com/github/dynamic/threadpool/console/controller/RoleController.java new file mode 100644 index 00000000..0139ebc9 --- /dev/null +++ b/console/src/main/java/com/github/dynamic/threadpool/console/controller/RoleController.java @@ -0,0 +1,50 @@ +package com.github.dynamic.threadpool.console.controller; + +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.github.dynamic.threadpool.auth.model.biz.role.RoleRespDTO; +import com.github.dynamic.threadpool.auth.service.RoleService; +import com.github.dynamic.threadpool.common.web.base.Result; +import com.github.dynamic.threadpool.common.web.base.Results; +import lombok.AllArgsConstructor; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +/** + * Role controller. + * + * @author chen.ma + * @date 2021/10/30 22:16 + */ +@RestController +@AllArgsConstructor +@RequestMapping("/v1/auth/roles") +public class RoleController { + + private final RoleService roleService; + + @GetMapping("/{pageNo}/{pageSize}") + public Result> listUser(@PathVariable("pageNo") int pageNo, @PathVariable("pageSize") int pageSize) { + IPage resultRolePage = roleService.listRole(pageNo, pageSize); + return Results.success(resultRolePage); + } + + @PostMapping("/{role}/{userName}") + public Result addUser(@PathVariable("role") String role, @PathVariable("userName") String userName) { + roleService.addRole(role, userName); + return Results.success(); + } + + @DeleteMapping("/{role}/{userName}") + public Result deleteUser(@PathVariable("role") String role, @PathVariable("userName") String userName) { + roleService.deleteRole(role, userName); + return Results.success(); + } + + @GetMapping("/search/{role}") + public Result> searchUsersLikeUserName(@PathVariable("role") String role) { + List resultRole = roleService.getRoleLike(role); + return Results.success(resultRole); + } + +} diff --git a/console/src/main/java/com/github/dynamic/threadpool/console/controller/UserController.java b/console/src/main/java/com/github/dynamic/threadpool/console/controller/UserController.java new file mode 100644 index 00000000..cb3acd61 --- /dev/null +++ b/console/src/main/java/com/github/dynamic/threadpool/console/controller/UserController.java @@ -0,0 +1,56 @@ +package com.github.dynamic.threadpool.console.controller; + +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.github.dynamic.threadpool.auth.model.biz.user.UserRespDTO; +import com.github.dynamic.threadpool.auth.service.UserService; +import com.github.dynamic.threadpool.common.web.base.Result; +import com.github.dynamic.threadpool.common.web.base.Results; +import lombok.AllArgsConstructor; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +/** + * User controller. + * + * @author chen.ma + * @date 2021/10/30 21:15 + */ +@RestController +@AllArgsConstructor +@RequestMapping({"/v1/auth", "/v1/auth/users"}) +public class UserController { + + private final UserService userService; + + @GetMapping("/{pageNo}/{pageSize}") + public Result> listUser(@PathVariable("pageNo") int pageNo, @PathVariable("pageSize") int pageSize) { + IPage resultUserPage = userService.listUser(pageNo, pageSize); + return Results.success(resultUserPage); + } + + @PostMapping("/{userName}/{password}") + public Result addUser(@PathVariable("userName") String userName, @PathVariable("password") String password) { + userService.addUser(userName, password); + return Results.success(); + } + + @PutMapping("/{userName}/{password}") + public Result updateUser(@PathVariable("userName") String userName, @PathVariable("password") String password) { + userService.updateUser(userName, password); + return Results.success(); + } + + @DeleteMapping("/{userName}") + public Result deleteUser(@PathVariable("userName") String userName) { + userService.deleteUser(userName); + return Results.success(); + } + + @GetMapping("/search/{userName}") + public Result> searchUsersLikeUserName(@PathVariable("userName") String userName) { + List resultUserNames = userService.getUserLikeUsername(userName); + return Results.success(resultUserNames); + } + +}