mirror of
https://github.com/APIParkLab/APIPark.git
synced 2026-06-26 16:01:56 +08:00
Merge branch 'feature/1.7-liujian' into 'main'
update api portal interface See merge request apipark/APIPark!325
This commit is contained in:
@@ -3,6 +3,7 @@ package catalogue
|
||||
import (
|
||||
"github.com/APIParkLab/APIPark/module/catalogue"
|
||||
catalogue_dto "github.com/APIParkLab/APIPark/module/catalogue/dto"
|
||||
"github.com/APIParkLab/APIPark/module/service"
|
||||
"github.com/APIParkLab/APIPark/module/tag"
|
||||
tag_dto "github.com/APIParkLab/APIPark/module/tag/dto"
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -14,6 +15,7 @@ var (
|
||||
|
||||
type imlCatalogueController struct {
|
||||
catalogueModule catalogue.ICatalogueModule `autowired:""`
|
||||
appModule service.IAppModule `autowired:""`
|
||||
tagModule tag.ITagModule `autowired:""`
|
||||
}
|
||||
|
||||
@@ -26,7 +28,17 @@ func (i *imlCatalogueController) Subscribe(ctx *gin.Context, subscribeInfo *cata
|
||||
}
|
||||
|
||||
func (i *imlCatalogueController) ServiceDetail(ctx *gin.Context, sid string) (*catalogue_dto.ServiceDetail, error) {
|
||||
return i.catalogueModule.ServiceDetail(ctx, sid)
|
||||
detail, err := i.catalogueModule.ServiceDetail(ctx, sid)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
_, canSubscribe, err := i.appModule.SearchCanSubscribe(ctx, sid)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
detail.CanSubscribe = canSubscribe
|
||||
return detail, nil
|
||||
|
||||
}
|
||||
|
||||
func (i *imlCatalogueController) Search(ctx *gin.Context, keyword string) ([]*catalogue_dto.Item, []*tag_dto.Item, error) {
|
||||
|
||||
@@ -542,8 +542,9 @@ type imlAppController struct {
|
||||
authModule application_authorization.IAuthorizationModule `autowired:""`
|
||||
}
|
||||
|
||||
func (i *imlAppController) SearchCanSubscribe(ctx *gin.Context, serviceId string) ([]*service_dto.SimpleAppItem, error) {
|
||||
return i.module.SearchCanSubscribe(ctx, serviceId)
|
||||
func (i *imlAppController) SearchCanSubscribe(ctx *gin.Context, serviceId string) ([]*service_dto.SubscribeAppItem, error) {
|
||||
items, _, err := i.module.SearchCanSubscribe(ctx, serviceId)
|
||||
return items, err
|
||||
}
|
||||
|
||||
func (i *imlAppController) Search(ctx *gin.Context, teamId string, keyword string) ([]*service_dto.AppItem, error) {
|
||||
|
||||
@@ -44,7 +44,7 @@ type IAppController interface {
|
||||
// SimpleApps 获取简易项目列表
|
||||
SimpleApps(ctx *gin.Context, keyword string) ([]*service_dto.SimpleAppItem, error)
|
||||
MySimpleApps(ctx *gin.Context, keyword string) ([]*service_dto.SimpleAppItem, error)
|
||||
SearchCanSubscribe(ctx *gin.Context, keyword string) ([]*service_dto.SimpleAppItem, error)
|
||||
SearchCanSubscribe(ctx *gin.Context, serviceId string) ([]*service_dto.SubscribeAppItem, error)
|
||||
GetApp(ctx *gin.Context, appId string) (*service_dto.App, error)
|
||||
DeleteApp(ctx *gin.Context, appId string) error
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ type ServiceDetail struct {
|
||||
OpenAPIAddress string `json:"openapi_address"`
|
||||
MCPServerAddress string `json:"mcp_server_address"`
|
||||
MCPAccessConfig string `json:"mcp_access_config"`
|
||||
CanSubscribe bool `json:"can_subscribe"`
|
||||
}
|
||||
|
||||
type ServiceBasic struct {
|
||||
|
||||
@@ -86,6 +86,12 @@ type SimpleAppItem struct {
|
||||
Description string `json:"description"`
|
||||
}
|
||||
|
||||
type SubscribeAppItem struct {
|
||||
Id string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
IsSubscribed bool `json:"is_subscribed"`
|
||||
}
|
||||
|
||||
type Service struct {
|
||||
Id string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
|
||||
+42
-37
@@ -861,65 +861,70 @@ type imlAppModule struct {
|
||||
transaction store.ITransaction `autowired:""`
|
||||
}
|
||||
|
||||
func (i *imlAppModule) SearchCanSubscribe(ctx context.Context, serviceId string) ([]*service_dto.SimpleAppItem, error) {
|
||||
func (i *imlAppModule) SearchCanSubscribe(ctx context.Context, serviceId string) ([]*service_dto.SubscribeAppItem, bool, error) {
|
||||
apps, err := i.searchMyApps(ctx, "", "")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
list, err := i.roleService.ListByPermit(ctx, access.SystemWorkspaceApplicationManagerAll)
|
||||
if err == nil && len(list) > 0 {
|
||||
return utils.SliceToSlice(apps, func(p *service.Service) *service_dto.SimpleAppItem {
|
||||
return &service_dto.SimpleAppItem{
|
||||
Id: p.Id,
|
||||
Name: p.Name,
|
||||
Description: p.Description,
|
||||
Team: auto.UUID(p.Team),
|
||||
}
|
||||
}), nil
|
||||
}
|
||||
list, err = i.roleService.ListByPermit(ctx, access.TeamConsumerSubscriptionSubscribe)
|
||||
if err != nil {
|
||||
return nil, nil
|
||||
}
|
||||
roleIds := utils.SliceToSlice(list, func(p *role.RoleByPermit) string {
|
||||
return p.Id
|
||||
})
|
||||
members, err := i.roleMemberService.ListByRoleIds(ctx, utils.UserId(ctx), roleIds...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(members) == 0 {
|
||||
return nil, nil
|
||||
return nil, false, err
|
||||
}
|
||||
subscribes, err := i.subscribeService.ListByServices(ctx, serviceId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, false, err
|
||||
}
|
||||
subscribeMap := utils.SliceToMapO(subscribes, func(p *subscribe.Subscribe) (string, struct{}) {
|
||||
return p.Application, struct{}{}
|
||||
}, func(s *subscribe.Subscribe) bool {
|
||||
return s.ApplyStatus == subscribe.ApplyStatusSubscribe
|
||||
})
|
||||
canSubscribe := false
|
||||
list, err := i.roleService.ListByPermit(ctx, access.SystemWorkspaceApplicationManagerAll)
|
||||
if err == nil && len(list) > 0 {
|
||||
return utils.SliceToSlice(apps, func(p *service.Service) *service_dto.SubscribeAppItem {
|
||||
_, isSubscribed := subscribeMap[p.Id]
|
||||
if !isSubscribed {
|
||||
canSubscribe = true
|
||||
}
|
||||
return &service_dto.SubscribeAppItem{
|
||||
Id: p.Id,
|
||||
Name: p.Name,
|
||||
IsSubscribed: isSubscribed,
|
||||
}
|
||||
}), canSubscribe, nil
|
||||
}
|
||||
list, err = i.roleService.ListByPermit(ctx, access.TeamConsumerSubscriptionSubscribe)
|
||||
if err != nil {
|
||||
return nil, false, nil
|
||||
}
|
||||
roleIds := utils.SliceToSlice(list, func(p *role.RoleByPermit) string {
|
||||
return p.Id
|
||||
})
|
||||
members, err := i.roleMemberService.ListByRoleIds(ctx, utils.UserId(ctx), roleIds...)
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
if len(members) == 0 {
|
||||
return nil, false, nil
|
||||
}
|
||||
|
||||
teamMap := utils.SliceToMapO(members, func(p *role.Member) (string, struct{}) {
|
||||
return role.TrimTeamTarget(p.Target), struct{}{}
|
||||
})
|
||||
result := make([]*service_dto.SimpleAppItem, 0, len(apps))
|
||||
result := make([]*service_dto.SubscribeAppItem, 0, len(apps))
|
||||
for _, app := range apps {
|
||||
if _, ok := teamMap[app.Team]; !ok {
|
||||
continue
|
||||
}
|
||||
if _, ok := subscribeMap[app.Id]; ok {
|
||||
continue
|
||||
_, isSubscribed := subscribeMap[app.Id]
|
||||
if !isSubscribed {
|
||||
canSubscribe = true
|
||||
}
|
||||
result = append(result, &service_dto.SimpleAppItem{
|
||||
Id: app.Id,
|
||||
Name: app.Name,
|
||||
Description: app.Description,
|
||||
Team: auto.UUID(app.Team),
|
||||
result = append(result, &service_dto.SubscribeAppItem{
|
||||
Id: app.Id,
|
||||
Name: app.Name,
|
||||
IsSubscribed: isSubscribed,
|
||||
})
|
||||
}
|
||||
|
||||
return result, nil
|
||||
return result, canSubscribe, nil
|
||||
}
|
||||
|
||||
func (i *imlAppModule) ExportAll(ctx context.Context) ([]*service_dto.ExportApp, error) {
|
||||
|
||||
@@ -51,7 +51,7 @@ type IAppModule interface {
|
||||
UpdateApp(ctx context.Context, appId string, input *service_dto.UpdateApp) (*service_dto.App, error)
|
||||
Search(ctx context.Context, teamId string, keyword string) ([]*service_dto.AppItem, error)
|
||||
SearchMyApps(ctx context.Context, teamId string, keyword string) ([]*service_dto.AppItem, error)
|
||||
SearchCanSubscribe(ctx context.Context, serviceId string) ([]*service_dto.SimpleAppItem, error)
|
||||
SearchCanSubscribe(ctx context.Context, serviceId string) ([]*service_dto.SubscribeAppItem, bool, error)
|
||||
// SimpleApps 获取简易项目列表
|
||||
SimpleApps(ctx context.Context, keyword string) ([]*service_dto.SimpleAppItem, error)
|
||||
MySimpleApps(ctx context.Context, keyword string) ([]*service_dto.SimpleAppItem, error)
|
||||
|
||||
Reference in New Issue
Block a user