|
|
@@ -0,0 +1,89 @@
|
|
|
+package com.zhongshu.card.server.core.controller.openAPI;
|
|
|
+
|
|
|
+import com.github.microservice.auth.client.constant.AuthConstant;
|
|
|
+import com.github.microservice.auth.security.annotations.ResourceAuth;
|
|
|
+import com.github.microservice.auth.security.type.AuthType;
|
|
|
+import com.zhongshu.opengateway.client.model.OpenApiConfigModel;
|
|
|
+import com.zhongshu.opengateway.client.model.param.AddApiParam;
|
|
|
+import com.zhongshu.opengateway.client.model.param.LimitParam;
|
|
|
+import com.zhongshu.opengateway.client.model.ret.ResultContent;
|
|
|
+import com.zhongshu.opengateway.client.service.OpenApiConfigService;
|
|
|
+import io.swagger.v3.oas.annotations.Operation;
|
|
|
+import io.swagger.v3.oas.annotations.tags.Tag;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.data.domain.Pageable;
|
|
|
+import org.springframework.data.domain.Sort;
|
|
|
+import org.springframework.data.web.PageableDefault;
|
|
|
+import org.springframework.http.MediaType;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+@RestController
|
|
|
+@RequestMapping("/openApi/apiConfig")
|
|
|
+@Tag(name = "OpenApi--接口管理")
|
|
|
+public class OpenApiConfigManagerController {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ OpenApiConfigService openApiConfigService;
|
|
|
+
|
|
|
+ @Operation(summary = "添加应用", description = "添加应用")
|
|
|
+ @ResourceAuth(value = AuthConstant.SuperAdmin, type = AuthType.Platform, remark = "")
|
|
|
+ @ResourceAuth(value = "openapi", type = AuthType.Project, remark = "")
|
|
|
+ @RequestMapping(value = "quoteOpenApi", method = RequestMethod.POST, consumes = {MediaType.ALL_VALUE})
|
|
|
+ public ResultContent quoteOpenApi(@RequestBody AddApiParam param){
|
|
|
+ return openApiConfigService.quoteOpenApi(param);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Operation(summary = "分页查询App下openApi", description = "分页查询App下openApi")
|
|
|
+ @ResourceAuth(value = AuthConstant.SuperAdmin, type = AuthType.Platform, remark = "")
|
|
|
+ @ResourceAuth(value = "openapi", type = AuthType.Project, remark = "")
|
|
|
+ @RequestMapping(value = "pageByApp", method = RequestMethod.POST, consumes = {MediaType.ALL_VALUE})
|
|
|
+ public ResultContent pageByApp(String appId, @PageableDefault(sort = "createTime", direction = Sort.Direction.DESC) Pageable pageable){
|
|
|
+
|
|
|
+ ResultContent<List<OpenApiConfigModel>> listRet = openApiConfigService.listByAppId(appId);
|
|
|
+ if (listRet.isFailed()){
|
|
|
+ return listRet;
|
|
|
+ }
|
|
|
+ List<OpenApiConfigModel> openApiConfigModelList = listRet.getContent();
|
|
|
+ Object[] openApiPathList = openApiConfigModelList.stream().map(it -> {
|
|
|
+ return it.getOpenApiModel().getPath();
|
|
|
+ }).toArray();
|
|
|
+
|
|
|
+ return openApiConfigService.pageByMql("{\"isDelete\": false, \"appId \" : \""+appId + "\", \"openApi.path\" : { $in: [\""+ StringUtils.join(openApiPathList, "\",\"") + "\"]}}", pageable);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Operation(summary = "禁用/启用", description = "禁用/启用")
|
|
|
+ @ResourceAuth(value = AuthConstant.SuperAdmin, type = AuthType.Platform, remark = "")
|
|
|
+ @ResourceAuth(value = "openapi", type = AuthType.Project, remark = "")
|
|
|
+ @RequestMapping(value = "disable", method = RequestMethod.POST, consumes = {MediaType.ALL_VALUE})
|
|
|
+ public ResultContent disable(String id){
|
|
|
+ return openApiConfigService.disable(id);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Operation(summary = "删除", description = "删除")
|
|
|
+ @ResourceAuth(value = AuthConstant.SuperAdmin, type = AuthType.Platform, remark = "")
|
|
|
+ @ResourceAuth(value = "openapi", type = AuthType.Project, remark = "")
|
|
|
+ @RequestMapping(value = "delete", method = RequestMethod.POST, consumes = {MediaType.ALL_VALUE})
|
|
|
+ public ResultContent delete(String id){
|
|
|
+ return openApiConfigService.delete(id);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Operation(summary = " 获取openApi详情", description = " 获取openApi详情")
|
|
|
+ @ResourceAuth(value = AuthConstant.SuperAdmin, type = AuthType.Platform, remark = "")
|
|
|
+ @ResourceAuth(value = "openapi", type = AuthType.Project, remark = "")
|
|
|
+ @RequestMapping(value = "get", method = RequestMethod.POST, consumes = {MediaType.ALL_VALUE})
|
|
|
+ public ResultContent get(String id){
|
|
|
+ return openApiConfigService.get(id);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Operation(summary = "设置限流规则", description = "设置限流规则")
|
|
|
+ @ResourceAuth(value = AuthConstant.SuperAdmin, type = AuthType.Platform, remark = "")
|
|
|
+ @ResourceAuth(value = "openapi", type = AuthType.Project, remark = "")
|
|
|
+ @RequestMapping(value = "setLimit", method = RequestMethod.POST, consumes = {MediaType.ALL_VALUE})
|
|
|
+ public ResultContent setLimit(@RequestBody LimitParam limitParam){
|
|
|
+ return openApiConfigService.setLimit(limitParam);
|
|
|
+ }
|
|
|
+}
|