Skip to content
This repository was archived by the owner on Mar 6, 2024. It is now read-only.

Commit 5a21eea

Browse files
committed
add swagger-api for auth, category, common and config controller
1 parent 7ac740d commit 5a21eea

File tree

4 files changed

+45
-0
lines changed

4 files changed

+45
-0
lines changed

src/main/java/com/zhazhapan/efo/web/controller/AuthController.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
import com.zhazhapan.efo.service.IAuthService;
66
import com.zhazhapan.efo.util.ControllerUtils;
77
import com.zhazhapan.util.Formatter;
8+
import io.swagger.annotations.Api;
9+
import io.swagger.annotations.ApiImplicitParam;
10+
import io.swagger.annotations.ApiImplicitParams;
11+
import io.swagger.annotations.ApiOperation;
812
import org.springframework.beans.factory.annotation.Autowired;
913
import org.springframework.web.bind.annotation.PathVariable;
1014
import org.springframework.web.bind.annotation.RequestMapping;
@@ -17,32 +21,43 @@
1721
*/
1822
@RestController
1923
@RequestMapping("/auth")
24+
@Api(value = "/auth", description = "权限表相关操作")
2025
public class AuthController {
2126

2227
private final IAuthService authService;
2328

2429
@Autowired
2530
public AuthController(IAuthService authService) {this.authService = authService;}
2631

32+
@ApiOperation(value = "添加权限记录", notes = "设置指定用户对指定文件的权限")
33+
@ApiImplicitParams({@ApiImplicitParam(name = "files", value = "文件", example = "file1,file2,file3", required = true),
34+
@ApiImplicitParam(name = "users", value = "用户", example = "user1,user2,user3", required = true),
35+
@ApiImplicitParam(name = "auths", value = "权限", example = "1,1,1,1", required = true)})
2736
@AuthInterceptor(InterceptorLevel.ADMIN)
2837
@RequestMapping(value = "", method = RequestMethod.POST)
2938
public String add(String files, String users, String auths) {
3039
System.out.println("files: " + files + " users: " + users + " auths: " + auths);
3140
return ControllerUtils.getResponse(authService.addAuth(files, users, auths));
3241
}
3342

43+
@ApiOperation(value = "获取权限记录")
44+
@ApiImplicitParams({@ApiImplicitParam(name = "user", value = "用户", required = true), @ApiImplicitParam(name =
45+
"file", value = "文件", required = true), @ApiImplicitParam(name = "offset", value = "偏移量", required = true)})
3446
@AuthInterceptor(InterceptorLevel.ADMIN)
3547
@RequestMapping(value = "/all", method = RequestMethod.GET)
3648
public String getAuth(String user, String file, int offset) {
3749
return Formatter.listToJson(authService.getAuth(user, file, offset));
3850
}
3951

52+
@ApiOperation(value = "更新权限记录")
53+
@ApiImplicitParams({@ApiImplicitParam(name = "auth", value = "权限值", required = true)})
4054
@AuthInterceptor(InterceptorLevel.ADMIN)
4155
@RequestMapping(value = "/{id}", method = RequestMethod.PUT)
4256
public String updateAuth(@PathVariable("id") long id, String auth) {
4357
return ControllerUtils.getResponse(authService.updateAuth(id, auth));
4458
}
4559

60+
@ApiOperation(value = "批量删除权限记录")
4661
@AuthInterceptor(InterceptorLevel.ADMIN)
4762
@RequestMapping(value = "/batch/{ids}", method = RequestMethod.DELETE)
4863
public String batchDelete(@PathVariable("ids") String ids) {

src/main/java/com/zhazhapan/efo/web/controller/CategoryController.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
import com.zhazhapan.modules.constant.ValueConsts;
99
import com.zhazhapan.util.Checker;
1010
import com.zhazhapan.util.Formatter;
11+
import io.swagger.annotations.Api;
12+
import io.swagger.annotations.ApiImplicitParam;
13+
import io.swagger.annotations.ApiOperation;
1114
import org.springframework.beans.factory.annotation.Autowired;
1215
import org.springframework.web.bind.annotation.PathVariable;
1316
import org.springframework.web.bind.annotation.RequestMapping;
@@ -20,32 +23,38 @@
2023
*/
2124
@RestController
2225
@RequestMapping("/category")
26+
@Api(value = "/category", description = "文件分类相关操作")
2327
public class CategoryController {
2428

2529
private final ICategoryService categoryService;
2630

2731
@Autowired
2832
public CategoryController(ICategoryService categoryService) {this.categoryService = categoryService;}
2933

34+
@ApiOperation(value = "新增一个分类")
3035
@AuthInterceptor(InterceptorLevel.ADMIN)
3136
@RequestMapping(value = "/{name}", method = RequestMethod.POST)
3237
public String add(@PathVariable("name") String name) {
3338
return ControllerUtils.getResponse(categoryService.insert(name));
3439
}
3540

41+
@ApiOperation(value = "更新分类名称")
42+
@ApiImplicitParam(name = "name", value = "新的名称", required = true)
3643
@AuthInterceptor(InterceptorLevel.ADMIN)
3744
@RequestMapping(value = "/{id}", method = RequestMethod.PUT)
3845
public String update(@PathVariable("id") int id, String name) {
3946
boolean isSuccess = Checker.isNotEmpty(name) && categoryService.update(id, name);
4047
return ControllerUtils.getResponse(isSuccess);
4148
}
4249

50+
@ApiOperation(value = "删除一个分类")
4351
@AuthInterceptor(InterceptorLevel.ADMIN)
4452
@RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
4553
public String remove(@PathVariable("id") int id) {
4654
return ControllerUtils.getResponse(categoryService.remove(id));
4755
}
4856

57+
@ApiOperation(value = "获取一个分类")
4958
@AuthInterceptor(InterceptorLevel.NONE)
5059
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
5160
public String getById(@PathVariable("id") int id) {
@@ -57,6 +66,7 @@ public String getById(@PathVariable("id") int id) {
5766
}
5867
}
5968

69+
@ApiOperation(value = "获取所有分类")
6070
@AuthInterceptor(InterceptorLevel.NONE)
6171
@RequestMapping(value = "/all", method = RequestMethod.GET)
6272
public String getAll() {

src/main/java/com/zhazhapan/efo/web/controller/CommonController.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
import com.zhazhapan.efo.util.ControllerUtils;
1010
import com.zhazhapan.modules.constant.ValueConsts;
1111
import com.zhazhapan.util.Checker;
12+
import io.swagger.annotations.Api;
13+
import io.swagger.annotations.ApiImplicitParam;
14+
import io.swagger.annotations.ApiOperation;
1215
import org.slf4j.Logger;
1316
import org.slf4j.LoggerFactory;
1417
import org.springframework.beans.factory.annotation.Autowired;
@@ -25,6 +28,7 @@
2528
*/
2629
@RestController
2730
@RequestMapping("/common")
31+
@Api(value = "/common", description = "公共接口")
2832
public class CommonController {
2933

3034
private static Logger logger = LoggerFactory.getLogger(ConfigController.class);
@@ -42,13 +46,16 @@ public CommonController(ICommonService commonService, HttpServletRequest request
4246
this.jsonObject = jsonObject;
4347
}
4448

49+
@ApiOperation(value = "获取头像资源")
4550
@AuthInterceptor(InterceptorLevel.NONE)
4651
@RequestMapping(value = "/avatar/{name}", method = RequestMethod.GET)
4752
public void getAvatar(HttpServletResponse response, @PathVariable("name") String name) throws IOException {
4853
String path = SettingConfig.getAvatarStoragePath() + ValueConsts.SEPARATOR + name;
4954
ControllerUtils.loadResource(response, path, ValueConsts.FALSE);
5055
}
5156

57+
@ApiOperation(value = "上传头像")
58+
@ApiImplicitParam(name = "multipartFile", value = "头像", required = true)
5259
@AuthInterceptor(InterceptorLevel.USER)
5360
@RequestMapping(value = "/avatar", method = RequestMethod.POST)
5461
public String avatarUpload(@RequestParam("file") MultipartFile multipartFile) {
@@ -61,6 +68,7 @@ public String avatarUpload(@RequestParam("file") MultipartFile multipartFile) {
6168
return jsonObject.toString();
6269
}
6370

71+
@ApiOperation(value = "发送验证码")
6472
@AuthInterceptor(InterceptorLevel.NONE)
6573
@RequestMapping(value = "/{email}/code", method = RequestMethod.POST)
6674
public String sendVerifyCode(@PathVariable("email") String email) {
@@ -75,6 +83,7 @@ public String sendVerifyCode(@PathVariable("email") String email) {
7583
return jsonObject.toString();
7684
}
7785

86+
@ApiOperation(value = "验证验证码是否正确")
7887
@AuthInterceptor(InterceptorLevel.NONE)
7988
@RequestMapping(value = "/{code}/verification", method = RequestMethod.PUT)
8089
public String verifyCode(@PathVariable("code") String code) {

src/main/java/com/zhazhapan/efo/web/controller/ConfigController.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
import com.zhazhapan.modules.constant.ValueConsts;
1010
import com.zhazhapan.util.FileExecutor;
1111
import com.zhazhapan.util.NetUtils;
12+
import io.swagger.annotations.Api;
13+
import io.swagger.annotations.ApiImplicitParam;
14+
import io.swagger.annotations.ApiOperation;
1215
import org.apache.log4j.Logger;
1316
import org.springframework.beans.factory.annotation.Autowired;
1417
import org.springframework.web.bind.annotation.RequestMapping;
@@ -24,10 +27,13 @@
2427
*/
2528
@RestController
2629
@RequestMapping("/config")
30+
@Api(value = "/config", description = "配置文件的相关操作")
2731
public class ConfigController {
2832

2933
private static Logger logger = Logger.getLogger(ConfigController.class);
34+
3035
private final IConfigService configService;
36+
3137
private final HttpServletRequest request;
3238

3339
@Autowired
@@ -36,6 +42,8 @@ public ConfigController(IConfigService configService, HttpServletRequest request
3642
this.request = request;
3743
}
3844

45+
@ApiOperation(value = "更新配置文件")
46+
@ApiImplicitParam(name = "config", value = "配置文件内容", required = true)
3947
@AuthInterceptor(InterceptorLevel.ADMIN)
4048
@RequestMapping(value = "", method = RequestMethod.PUT)
4149
public String updateConfig(String config) {
@@ -56,6 +64,7 @@ public String updateConfig(String config) {
5664
}
5765
}
5866

67+
@ApiOperation(value = "获取配置文件内容")
5968
@AuthInterceptor(InterceptorLevel.ADMIN)
6069
@RequestMapping(value = "/all", method = RequestMethod.GET)
6170
public String getAll() {
@@ -67,12 +76,14 @@ public String getAll() {
6776
}
6877
}
6978

79+
@ApiOperation(value = "获取配置文件中的全局相关配置内容")
7080
@AuthInterceptor(InterceptorLevel.NONE)
7181
@RequestMapping(value = "/global", method = RequestMethod.GET)
7282
public String getGlobalConfig() {
7383
return configService.getGlobalConfig();
7484
}
7585

86+
@ApiOperation(value = "获取配置文件中的用户相关配置内容")
7687
@AuthInterceptor(InterceptorLevel.NONE)
7788
@RequestMapping(value = "/user", method = RequestMethod.GET)
7889
public String getUserConfig() {

0 commit comments

Comments
 (0)