summaryrefslogtreecommitdiff
path: root/src/main/java/com/mesasoft/cn/web/controller/AuthController.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/mesasoft/cn/web/controller/AuthController.java')
-rw-r--r--src/main/java/com/mesasoft/cn/web/controller/AuthController.java66
1 files changed, 66 insertions, 0 deletions
diff --git a/src/main/java/com/mesasoft/cn/web/controller/AuthController.java b/src/main/java/com/mesasoft/cn/web/controller/AuthController.java
new file mode 100644
index 0000000..24a4a0b
--- /dev/null
+++ b/src/main/java/com/mesasoft/cn/web/controller/AuthController.java
@@ -0,0 +1,66 @@
+package com.mesasoft.cn.web.controller;
+
+import com.mesasoft.cn.annotation.AuthInterceptor;
+import com.mesasoft.cn.enums.InterceptorLevel;
+import com.mesasoft.cn.service.IAuthService;
+import com.mesasoft.cn.util.ControllerUtils;
+import com.zhazhapan.util.Formatter;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiImplicitParam;
+import io.swagger.annotations.ApiImplicitParams;
+import io.swagger.annotations.ApiOperation;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * @author pantao
+ * @since 2018/3/8
+ */
+@RestController
+@RequestMapping("/auth")
+@Api(value = "/auth", description = "权限表相关操作")
+public class AuthController {
+
+ private final IAuthService authService;
+
+ @Autowired
+ public AuthController(IAuthService authService) {this.authService = authService;}
+
+ @ApiOperation(value = "添加权限记录", notes = "设置指定用户对指定文件的权限")
+ @ApiImplicitParams({@ApiImplicitParam(name = "files", value = "文件", example = "file1,file2,file3", required = true),
+ @ApiImplicitParam(name = "users", value = "用户", example = "user1,user2,user3", required = true),
+ @ApiImplicitParam(name = "auths", value = "权限", example = "1,1,1,1", required = true)})
+ @AuthInterceptor(InterceptorLevel.ADMIN)
+ @RequestMapping(value = "", method = RequestMethod.POST)
+ public String add(String files, String users, String auths) {
+ System.out.println("files: " + files + " users: " + users + " auths: " + auths);
+ return ControllerUtils.getResponse(authService.addAuth(files, users, auths));
+ }
+
+ @ApiOperation(value = "获取权限记录")
+ @ApiImplicitParams({@ApiImplicitParam(name = "user", value = "用户", required = true), @ApiImplicitParam(name =
+ "file", value = "文件", required = true), @ApiImplicitParam(name = "offset", value = "偏移量", required = true)})
+ @AuthInterceptor(InterceptorLevel.ADMIN)
+ @RequestMapping(value = "/all", method = RequestMethod.GET)
+ public String getAuth(String user, String file, int offset) {
+ return Formatter.listToJson(authService.listAuth(user, file, offset));
+ }
+
+ @ApiOperation(value = "更新权限记录")
+ @ApiImplicitParams({@ApiImplicitParam(name = "auth", value = "权限值", required = true)})
+ @AuthInterceptor(InterceptorLevel.ADMIN)
+ @RequestMapping(value = "/{id}", method = RequestMethod.PUT)
+ public String updateAuth(@PathVariable("id") long id, String auth) {
+ return ControllerUtils.getResponse(authService.updateAuth(id, auth));
+ }
+
+ @ApiOperation(value = "批量删除权限记录")
+ @AuthInterceptor(InterceptorLevel.ADMIN)
+ @RequestMapping(value = "/batch/{ids}", method = RequestMethod.DELETE)
+ public String batchDelete(@PathVariable("ids") String ids) {
+ return ControllerUtils.getResponse(authService.batchDelete(ids));
+ }
+}