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

Commit d6fb0b5

Browse files
committed
add swagger-api for all controller
1 parent 5a21eea commit d6fb0b5

9 files changed

+139
-15
lines changed

src/main/java/com/zhazhapan/efo/dao/sqlprovider/FileSqlProvider.java

+9-4
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public String updateAuthById() {
2424
*
2525
* @param userId 用户编号
2626
* @param fileId 文件编号
27+
*
2728
* @return SQL语句
2829
*/
2930
public String getBasicBy(@Param("userId") int userId, @Param("fileId") long fileId, @Param("fileName") String
@@ -54,7 +55,7 @@ public String getBasicBy(@Param("userId") int userId, @Param("fileId") long file
5455
private String getSqlEnds(int offset, String orderBy, String search) {
5556
int size = EfoApplication.settings.getIntegerUseEval(ConfigConsts.FILE_PAGE_SIZE_OF_SETTING);
5657
return getSearch(search) + " order by " + (Checker.isEmpty(orderBy) ? EfoApplication.settings
57-
.getStringUseEval(ConfigConsts.FILE_ORDER_BY_OF_SETTING) : orderBy) + " " + "limit " + offset * size
58+
.getStringUseEval(ConfigConsts.FILE_ORDER_BY_OF_SETTING) : orderBy) + " limit " + offset * size
5859
+ "," + size;
5960
}
6061

@@ -78,9 +79,13 @@ public String getUserDownloaded(@Param("offset") int offset, @Param("search") St
7879
}
7980

8081
private String getSearch(String search) {
81-
search = "'%" + Checker.checkNull(search) + "%'";
82-
return search.length() < 5 ? "" : " and (f.name like " + search + " or f.visit_url like " + search + " or " +
83-
"f" + "" + ".description like " + search + " or f.tag like " + search + ")";
82+
if (Checker.isEmpty(search)) {
83+
return ValueConsts.EMPTY_STRING;
84+
} else {
85+
search = "'%" + search + "%'";
86+
return " and (f.name like " + search + " or f.visit_url like " + search + " or f.description like " +
87+
search + " or f.tag like " + search + ")";
88+
}
8489
}
8590

8691
private String getBaseSql(boolean isDownloaded) {

src/main/java/com/zhazhapan/efo/service/impl/FileServiceImpl.java

+10-6
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,9 @@ public boolean deleteFiles(String ids) {
114114
Exception.class)
115115
public boolean[] updateUrl(int id, String oldLocalUrl, String localUrl, String visitUrl) {
116116
boolean[] b = new boolean[]{false, false};
117-
if (Checker.isNotEmpty(localUrl) && Checker.isNotExists(localUrl) && !localUrlExists(localUrl)) {
117+
boolean canUpdateLocalUrl = Checker.isExists(oldLocalUrl) && Checker.isNotEmpty(localUrl) && Checker
118+
.isNotExists(localUrl) && !localUrlExists(localUrl);
119+
if (canUpdateLocalUrl) {
118120
FileExecutor.renameTo(oldLocalUrl, localUrl);
119121
fileDAO.updateLocalUrlById(id, localUrl);
120122
b[0] = true;
@@ -278,7 +280,7 @@ public boolean upload(int categoryId, String tag, String description, String pre
278280
maxSize + "]");
279281
if (canUpload) {
280282
String visitUrl = getRegularVisitUrl(Checker.isNotEmpty(prefix) && user.getPermission() > 1 ? prefix
281-
: EfoApplication.settings.getStringUseEval(ConfigConsts.CUSTOM_LINK_RULE_OF_SETTING), user,
283+
: EfoApplication.settings.getStringUseEval(ConfigConsts.CUSTOM_LINK_RULE_OF_SETTING), user,
282284
name, suffix, category);
283285
if (fileExists) {
284286
removeByLocalUrl(localUrl);
@@ -318,10 +320,12 @@ public boolean upload(int categoryId, String tag, String description, String pre
318320
private String getRegularVisitUrl(String customUrl, User user, String fileName, String suffix, Category category) {
319321
Date date = new Date();
320322
suffix = suffix.startsWith(".") ? "" : "." + suffix;
321-
try {
322-
customUrl = URLDecoder.decode(customUrl, "utf-8");
323-
} catch (UnsupportedEncodingException e) {
324-
logger.error(e.getMessage());
323+
if (Checker.isNotEmpty(customUrl)) {
324+
try {
325+
customUrl = URLDecoder.decode(customUrl, "utf-8");
326+
} catch (UnsupportedEncodingException e) {
327+
logger.error(e.getMessage());
328+
}
325329
}
326330
if (!customUrl.contains(FILE_NAME) && !customUrl.contains(RANDOM_ID)) {
327331
customUrl += (customUrl.endsWith("/") ? "" : "/") + fileName;

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

+7
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,39 @@
22

33
import com.zhazhapan.efo.annotation.AuthInterceptor;
44
import com.zhazhapan.efo.enums.InterceptorLevel;
5+
import io.swagger.annotations.Api;
6+
import io.swagger.annotations.ApiOperation;
57
import org.springframework.boot.web.servlet.error.ErrorController;
68
import org.springframework.http.HttpStatus;
79
import org.springframework.stereotype.Controller;
810
import org.springframework.web.bind.annotation.RequestMapping;
911
import org.springframework.web.bind.annotation.ResponseStatus;
12+
import springfox.documentation.annotations.ApiIgnore;
1013

1114
/**
1215
* @author pantao
1316
* @since 2018/1/22
1417
*/
1518
@Controller
19+
@Api(description = "错误页面映射")
1620
public class CustomErrorController implements ErrorController {
1721

22+
@ApiOperation(value = "异常页面")
1823
@AuthInterceptor(InterceptorLevel.NONE)
1924
@RequestMapping("/exception")
2025
public String handleError() {
2126
return "error";
2227
}
2328

29+
@ApiOperation(value = "404、错误页面")
2430
@AuthInterceptor(InterceptorLevel.NONE)
2531
@RequestMapping("/error")
2632
@ResponseStatus(HttpStatus.NOT_FOUND)
2733
public String handleNotFound() {
2834
return "/404";
2935
}
3036

37+
@ApiIgnore
3138
@Override
3239
public String getErrorPath() {
3340
return "/error";

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

+9
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
import com.zhazhapan.efo.enums.InterceptorLevel;
55
import com.zhazhapan.efo.service.IDownloadedService;
66
import com.zhazhapan.util.Formatter;
7+
import io.swagger.annotations.Api;
8+
import io.swagger.annotations.ApiImplicitParam;
9+
import io.swagger.annotations.ApiImplicitParams;
10+
import io.swagger.annotations.ApiOperation;
711
import org.springframework.beans.factory.annotation.Autowired;
812
import org.springframework.web.bind.annotation.RequestMapping;
913
import org.springframework.web.bind.annotation.RequestMethod;
@@ -15,6 +19,7 @@
1519
*/
1620
@RestController
1721
@RequestMapping(value = "/downloaded")
22+
@Api(value = "/downloaded", description = "下载记录相关操作")
1823
public class DownloadedController {
1924

2025
private final IDownloadedService downloadService;
@@ -24,6 +29,10 @@ public DownloadedController(IDownloadedService downloadService) {
2429
this.downloadService = downloadService;
2530
}
2631

32+
@ApiOperation(value = "获取文件下载记录")
33+
@ApiImplicitParams({@ApiImplicitParam(name = "user", value = "指定用户(默认所有用户)"), @ApiImplicitParam(name =
34+
"指定文件(默认所有文件)"), @ApiImplicitParam(name = "category", value = "指定分类(默认所有分类)"), @ApiImplicitParam(name =
35+
"offset", value = "偏移量", required = true)})
2736
@AuthInterceptor(InterceptorLevel.ADMIN)
2837
@RequestMapping(value = "all", method = RequestMethod.GET)
2938
public String getAll(String user, String file, String category, int offset) {

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

+41
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
import com.zhazhapan.util.Checker;
1515
import com.zhazhapan.util.FileExecutor;
1616
import com.zhazhapan.util.Formatter;
17+
import io.swagger.annotations.Api;
18+
import io.swagger.annotations.ApiImplicitParam;
19+
import io.swagger.annotations.ApiImplicitParams;
20+
import io.swagger.annotations.ApiOperation;
1721
import org.springframework.beans.factory.annotation.Autowired;
1822
import org.springframework.web.bind.annotation.*;
1923
import org.springframework.web.multipart.MultipartFile;
@@ -29,6 +33,7 @@
2933
*/
3034
@RestController
3135
@RequestMapping("/file")
36+
@Api(value = "/file", description = "文件相关操作")
3237
public class FileController {
3338

3439
private final IFileService fileService;
@@ -44,20 +49,30 @@ public FileController(IFileService fileService, HttpServletRequest request, JSON
4449
this.jsonObject = jsonObject;
4550
}
4651

52+
@ApiOperation(value = "获取我的下载记录")
53+
@ApiImplicitParams({@ApiImplicitParam(name = "offset", value = "偏移量", required = true), @ApiImplicitParam(name =
54+
"search", value = "记录匹配(允许为空)")})
4755
@AuthInterceptor(InterceptorLevel.USER)
4856
@RequestMapping(value = "/user/downloaded", method = RequestMethod.GET)
4957
public String getUserDownloaded(int offset, String search) {
5058
User user = (User) request.getSession().getAttribute(ValueConsts.USER_STRING);
5159
return Formatter.listToJson(fileService.getUserDownloaded(user.getId(), offset, search));
5260
}
5361

62+
@ApiOperation(value = "获取我的上传记录")
63+
@ApiImplicitParams({@ApiImplicitParam(name = "offset", value = "偏移量", required = true), @ApiImplicitParam(name =
64+
"search", value = "记录匹配(允许为空)")})
5465
@AuthInterceptor(InterceptorLevel.USER)
5566
@RequestMapping(value = "/user/uploaded", method = RequestMethod.GET)
5667
public String getUserUploaded(int offset, String search) {
5768
User user = (User) request.getSession().getAttribute(ValueConsts.USER_STRING);
5869
return Formatter.listToJson(fileService.getUserUploaded(user.getId(), offset, search));
5970
}
6071

72+
@ApiOperation(value = "文件上传")
73+
@ApiImplicitParams({@ApiImplicitParam(name = "categoryId", value = "分类ID", required = true), @ApiImplicitParam
74+
(name = "tag", value = "文件标签"), @ApiImplicitParam(name = "description", value = "文件描述"),
75+
@ApiImplicitParam(name = "prefix", value = "文件前缀(仅适用于管理员上传文件,普通用户无效)")})
6176
@AuthInterceptor(InterceptorLevel.USER)
6277
@RequestMapping(value = "", method = RequestMethod.POST)
6378
public String upload(int categoryId, String tag, String description, String prefix, @RequestParam("file")
@@ -67,6 +82,10 @@ public String upload(int categoryId, String tag, String description, String pref
6782
user));
6883
}
6984

85+
@ApiOperation(value = "获取文件记录")
86+
@ApiImplicitParams({@ApiImplicitParam(name = "offset", value = "偏移量", required = true), @ApiImplicitParam(name =
87+
"categoryId", value = "分类ID", required = true), @ApiImplicitParam(name = "orderBy", value = "排序方式",
88+
required = true, example = "id desc"), @ApiImplicitParam(name = "search", value = "记录匹配(允许为空)")})
7089
@AuthInterceptor(InterceptorLevel.NONE)
7190
@RequestMapping(value = "/all", method = RequestMethod.GET)
7291
public String getAll(int offset, int categoryId, String orderBy, String search) {
@@ -82,6 +101,7 @@ public String getAll(int offset, int categoryId, String orderBy, String search)
82101
}
83102
}
84103

104+
@ApiOperation(value = "删除指定文件")
85105
@AuthInterceptor(InterceptorLevel.USER)
86106
@RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
87107
public String removeFile(@PathVariable("id") long id) {
@@ -99,6 +119,10 @@ public String removeFile(@PathVariable("id") long id) {
99119
return jsonObject.toString();
100120
}
101121

122+
@ApiOperation(value = "更新文件属性")
123+
@ApiImplicitParams({@ApiImplicitParam(name = "name", value = "文件名", required = true), @ApiImplicitParam(name =
124+
"category", value = "分类名称", required = true), @ApiImplicitParam(name = "tag", value = "文件标签", required =
125+
true), @ApiImplicitParam(name = "description", value = "文件描述", required = true)})
102126
@AuthInterceptor(InterceptorLevel.USER)
103127
@RequestMapping(value = "/{id}", method = RequestMethod.PUT)
104128
public String updateFileInfo(@PathVariable("id") long id, String name, String category, String tag, String
@@ -113,12 +137,18 @@ public String updateFileInfo(@PathVariable("id") long id, String name, String ca
113137
return jsonObject.toString();
114138
}
115139

140+
@ApiOperation(value = "获取所有文件的基本信息")
141+
@ApiImplicitParams({@ApiImplicitParam(name = "user", value = "指定用户(默认所有用户)"), @ApiImplicitParam(name = "file",
142+
value = "指定文件(默认所有文件)"), @ApiImplicitParam(name = "category", value = "指定分类(默认所有分类)"), @ApiImplicitParam
143+
(name = "offset", value = "偏移量", required = true)})
116144
@AuthInterceptor(InterceptorLevel.ADMIN)
117145
@RequestMapping(value = "/basic/all", method = RequestMethod.GET)
118146
public String getBasicAll(String user, String file, String category, int offset) {
119147
return Formatter.listToJson(fileService.getBasicAll(user, file, category, offset));
120148
}
121149

150+
@ApiOperation(value = "通过文件路径获取服务器端的文件")
151+
@ApiImplicitParam(name = "path", value = "文件路径(默认根目录)")
122152
@AuthInterceptor(InterceptorLevel.ADMIN)
123153
@RequestMapping(value = "/server", method = RequestMethod.GET)
124154
public String getServerFilesByPath(String path) {
@@ -132,13 +162,19 @@ public String getServerFilesByPath(String path) {
132162
return array.toJSONString();
133163
}
134164

165+
@ApiOperation("分享服务器端文件")
166+
@ApiImplicitParams({@ApiImplicitParam(name = "prefix", value = "自定义前缀(可空)"), @ApiImplicitParam(name = "files",
167+
value = "文件", required = true, example = "file1,file2,file3")})
135168
@AuthInterceptor(InterceptorLevel.ADMIN)
136169
@RequestMapping(value = "/server/share", method = RequestMethod.POST)
137170
public String shareFile(String prefix, String files) {
138171
User user = (User) request.getSession().getAttribute(ValueConsts.USER_STRING);
139172
return ControllerUtils.getResponse(fileService.shareFiles(Checker.checkNull(prefix), files, user));
140173
}
141174

175+
@ApiOperation(value = "更新文件路径(包括本地路径,访问路径,如果新的本地路径和访问路径均为空,这什么也不会做)")
176+
@ApiImplicitParams({@ApiImplicitParam(name = "oldLocalUrl", value = "文件本地路径", required = true), @ApiImplicitParam
177+
(name = "localUrl", value = "新的本地路径(可空)"), @ApiImplicitParam(name = "visitUrl", value = "新的访问路径(可空)")})
142178
@AuthInterceptor(InterceptorLevel.ADMIN)
143179
@RequestMapping(value = "/{id}/url", method = RequestMethod.PUT)
144180
public String uploadFileUrl(@PathVariable("id") int id, String oldLocalUrl, String localUrl, String visitUrl) {
@@ -147,18 +183,22 @@ public String uploadFileUrl(@PathVariable("id") int id, String oldLocalUrl, Stri
147183
return Formatter.formatJson(responseJson);
148184
}
149185

186+
@ApiOperation(value = "批量删除文件")
150187
@AuthInterceptor(InterceptorLevel.ADMIN)
151188
@RequestMapping(value = "/batch/{ids}", method = RequestMethod.DELETE)
152189
public String deleteFiles(@PathVariable("ids") String ids) {
153190
return ControllerUtils.getResponse(fileService.deleteFiles(ids));
154191
}
155192

193+
@ApiOperation(value = "获取指定文件的权限记录")
156194
@AuthInterceptor(InterceptorLevel.ADMIN)
157195
@RequestMapping(value = "/{id}/auth", method = RequestMethod.GET)
158196
public String getAuth(@PathVariable("id") long id) {
159197
return BeanUtils.toPrettyJson(fileService.getAuth(id));
160198
}
161199

200+
@ApiOperation(value = "更新指定文件的权限")
201+
@ApiImplicitParam(name = "auth", value = "权限", required = true, example = "1,1,1,1")
162202
@AuthInterceptor(InterceptorLevel.ADMIN)
163203
@RequestMapping(value = "/{id}/auth", method = RequestMethod.PUT)
164204
public String updateAuth(@PathVariable("id") long id, String auth) {
@@ -170,6 +210,7 @@ public String updateAuth(@PathVariable("id") long id, String auth) {
170210
*
171211
* @param response {@link HttpServletResponse}
172212
*/
213+
@ApiOperation(value = "通过访问路径获取文件资源")
173214
@AuthInterceptor(InterceptorLevel.NONE)
174215
@RequestMapping(value = "/**", method = RequestMethod.GET)
175216
public void getResource(HttpServletResponse response) throws IOException {

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

+8-5
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import java.io.IOException;
1717

1818
/**
19-
* filemanager api
2019
* <a href="https://github.com/joni2back/angular-filemanager/blob/master/API.md">see api doc</a>
2120
*
2221
* @author pantao
@@ -73,10 +72,14 @@ public void download(HttpServletResponse response, String path) throws IOExcepti
7372
@RequestMapping(value = "/upload", method = RequestMethod.POST)
7473
public String upload(String destination, @RequestParam("file-0") MultipartFile file0, @Nullable @RequestParam
7574
("file-1") MultipartFile file1, @Nullable @RequestParam("file-2") MultipartFile file2, @Nullable
76-
@RequestParam("file-3") MultipartFile file3, @Nullable @RequestParam("file-4") MultipartFile file4, @Nullable
77-
@RequestParam("file-5") MultipartFile file5, @Nullable @RequestParam("file-6") MultipartFile file6, @Nullable
78-
@RequestParam("file-7") MultipartFile file7, @Nullable @RequestParam("file-8") MultipartFile file8, @Nullable
79-
@RequestParam("file-9") MultipartFile file9, @Nullable @RequestParam("file-10") MultipartFile file10) {
75+
@RequestParam("file-3") MultipartFile file3, @Nullable @RequestParam("file-4") MultipartFile
76+
file4, @Nullable
77+
@RequestParam("file-5") MultipartFile file5, @Nullable @RequestParam("file-6") MultipartFile
78+
file6, @Nullable
79+
@RequestParam("file-7") MultipartFile file7, @Nullable @RequestParam("file-8") MultipartFile
80+
file8, @Nullable
81+
@RequestParam("file-9") MultipartFile file9, @Nullable @RequestParam("file-10")
82+
MultipartFile file10) {
8083
jsonObject.put("result", fileManagerService.upload(destination, file0, file1, file2, file3, file4, file5,
8184
file6, file7, file8, file9, file10));
8285
return jsonObject.toJSONString();

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

+9
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
import com.zhazhapan.efo.enums.InterceptorLevel;
55
import com.zhazhapan.efo.service.IUploadedService;
66
import com.zhazhapan.util.Formatter;
7+
import io.swagger.annotations.Api;
8+
import io.swagger.annotations.ApiImplicitParam;
9+
import io.swagger.annotations.ApiImplicitParams;
10+
import io.swagger.annotations.ApiOperation;
711
import org.springframework.beans.factory.annotation.Autowired;
812
import org.springframework.web.bind.annotation.RequestMapping;
913
import org.springframework.web.bind.annotation.RequestMethod;
@@ -15,13 +19,18 @@
1519
*/
1620
@RestController
1721
@RequestMapping(value = "/uploaded")
22+
@Api(value = "/uploaded", description = "上传记录相关操作")
1823
public class UploadedController {
1924

2025
private final IUploadedService uploadedService;
2126

2227
@Autowired
2328
public UploadedController(IUploadedService uploadedService) {this.uploadedService = uploadedService;}
2429

30+
@ApiOperation(value = "获取文件上传记录")
31+
@ApiImplicitParams({@ApiImplicitParam(name = "user", value = "指定用户(默认所有用户)"), @ApiImplicitParam(name =
32+
"指定文件(默认所有文件)"), @ApiImplicitParam(name = "category", value = "指定分类(默认所有分类)"), @ApiImplicitParam(name =
33+
"offset", value = "偏移量", required = true)})
2534
@AuthInterceptor(InterceptorLevel.ADMIN)
2635
@RequestMapping(value = "all", method = RequestMethod.GET)
2736
public String getAll(String user, String file, String category, int offset) {

0 commit comments

Comments
 (0)