diff --git a/controller/router/iml.go b/controller/router/iml.go index d4aa2023..4e698924 100644 --- a/controller/router/iml.go +++ b/controller/router/iml.go @@ -1,12 +1,13 @@ package router import ( + "io" + api_doc "github.com/APIParkLab/APIPark/module/api-doc" api_doc_dto "github.com/APIParkLab/APIPark/module/api-doc/dto" "github.com/APIParkLab/APIPark/module/router" router_dto "github.com/APIParkLab/APIPark/module/router/dto" "github.com/gin-gonic/gin" - "io" ) var _ IRouterController = (*imlAPIController)(nil) @@ -15,6 +16,10 @@ type imlAPIController struct { module router.IRouterModule `autowired:""` } +func (i *imlAPIController) Simple(ctx *gin.Context, input *router_dto.InputSimpleAPI) ([]*router_dto.SimpleItem, error) { + return i.module.SimpleAPIs(ctx, input) +} + func (i *imlAPIController) Detail(ctx *gin.Context, serviceId string, apiId string) (*router_dto.Detail, error) { return i.module.Detail(ctx, serviceId, apiId) } diff --git a/controller/router/router.go b/controller/router/router.go index a406947e..f682ba32 100644 --- a/controller/router/router.go +++ b/controller/router/router.go @@ -1,9 +1,10 @@ package router import ( - api_doc_dto "github.com/APIParkLab/APIPark/module/api-doc/dto" "reflect" + api_doc_dto "github.com/APIParkLab/APIPark/module/api-doc/dto" + "github.com/gin-gonic/gin" "github.com/eolinker/go-common/autowire" @@ -24,6 +25,7 @@ type IRouterController interface { Delete(ctx *gin.Context, serviceId string, apiId string) error // Prefix 获取API前缀 Prefix(ctx *gin.Context, serviceId string) (string, bool, error) + Simple(ctx *gin.Context, input *router_dto.InputSimpleAPI) ([]*router_dto.SimpleItem, error) } type IAPIDocController interface { diff --git a/module/router/dto/input.go b/module/router/dto/input.go index aee44807..02fcbf10 100644 --- a/module/router/dto/input.go +++ b/module/router/dto/input.go @@ -102,3 +102,7 @@ type ListInput struct { type UpdateDoc struct { Content string `json:"content"` } + +type InputSimpleAPI struct { + Services []string `json:"services"` +} diff --git a/module/router/dto/output.go b/module/router/dto/output.go index 45fe4888..9f8276ed 100644 --- a/module/router/dto/output.go +++ b/module/router/dto/output.go @@ -26,8 +26,8 @@ type Item struct { type SimpleItem struct { Id string `json:"id"` Methods []string `json:"methods"` - //Name string `json:"name"` - Path string `json:"request_path"` + Name string `json:"name"` + Path string `json:"request_path"` } type Detail struct { diff --git a/module/router/iml.go b/module/router/iml.go index 2be55575..e810c0e5 100644 --- a/module/router/iml.go +++ b/module/router/iml.go @@ -46,6 +46,28 @@ type imlRouterModule struct { transaction store.ITransaction `autowired:""` } +func (i *imlRouterModule) SimpleAPIs(ctx context.Context, input *router_dto.InputSimpleAPI) ([]*router_dto.SimpleItem, error) { + list, err := i.apiService.ListForServices(ctx, input.Services...) + if err != nil { + return nil, err + } + apiInfos, err := i.apiService.ListInfo(ctx, utils.SliceToSlice(list, func(s *api.API) string { + return s.UUID + })...) + if err != nil { + return nil, err + } + + return utils.SliceToSlice(apiInfos, func(item *api.Info) *router_dto.SimpleItem { + return &router_dto.SimpleItem{ + Id: item.UUID, + Name: item.Name, + Methods: item.Methods, + Path: item.Path, + } + }), nil +} + func (i *imlRouterModule) ExportAll(ctx context.Context) ([]*router_dto.Export, error) { apiList, err := i.apiService.ListInfo(ctx) diff --git a/module/router/router.go b/module/router/router.go index 36c83273..ae433518 100644 --- a/module/router/router.go +++ b/module/router/router.go @@ -31,6 +31,7 @@ type IRouterModule interface { // Prefix 获取API前缀 Prefix(ctx context.Context, serviceId string) (string, error) + SimpleAPIs(ctx context.Context, input *router_dto.InputSimpleAPI) ([]*router_dto.SimpleItem, error) //ExportAll(ctx context.Context) ([]*router_dto.Export, error) } diff --git a/plugins/core/api.go b/plugins/core/api.go index 666cf769..62def55b 100644 --- a/plugins/core/api.go +++ b/plugins/core/api.go @@ -9,6 +9,7 @@ import ( func (p *plugin) apiApis() []pm3.Api { return []pm3.Api{ + pm3.CreateApiWidthDoc(http.MethodPost, "/api/v1/simple/service/apis", []string{"context", "body"}, []string{"apis"}, p.routerController.Simple), pm3.CreateApiWidthDoc(http.MethodGet, "/api/v1/service/routers", []string{"context", "query:keyword", "query:service"}, []string{"routers"}, p.routerController.Search, access.SystemWorkspaceServiceViewAll, access.TeamServiceApiView), pm3.CreateApiWidthDoc(http.MethodGet, "/api/v1/service/router/detail", []string{"context", "query:service", "query:router"}, []string{"router"}, p.routerController.Detail, access.SystemWorkspaceServiceViewAll, access.TeamServiceApiView), pm3.CreateApiWidthDoc(http.MethodPost, "/api/v1/service/router", []string{"context", "query:service", "body"}, []string{"router"}, p.routerController.Create, access.SystemWorkspaceServiceManagerAll, access.TeamServiceApiManager),