Skip to content

Commit 8365f77

Browse files
committed
update api portal interface
1 parent 96f675a commit 8365f77

7 files changed

Lines changed: 60 additions & 35 deletions

File tree

controller/catalogue/iml.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package catalogue
33
import (
44
"github.com/APIParkLab/APIPark/module/catalogue"
55
catalogue_dto "github.com/APIParkLab/APIPark/module/catalogue/dto"
6+
"github.com/APIParkLab/APIPark/module/service"
67
"github.com/APIParkLab/APIPark/module/tag"
78
tag_dto "github.com/APIParkLab/APIPark/module/tag/dto"
89
"github.com/gin-gonic/gin"
@@ -14,6 +15,7 @@ var (
1415

1516
type imlCatalogueController struct {
1617
catalogueModule catalogue.ICatalogueModule `autowired:""`
18+
appModule service.IAppModule `autowired:""`
1719
tagModule tag.ITagModule `autowired:""`
1820
}
1921

@@ -26,7 +28,17 @@ func (i *imlCatalogueController) Subscribe(ctx *gin.Context, subscribeInfo *cata
2628
}
2729

2830
func (i *imlCatalogueController) ServiceDetail(ctx *gin.Context, sid string) (*catalogue_dto.ServiceDetail, error) {
29-
return i.catalogueModule.ServiceDetail(ctx, sid)
31+
detail, err := i.catalogueModule.ServiceDetail(ctx, sid)
32+
if err != nil {
33+
return nil, err
34+
}
35+
_, canSubscribe, err := i.appModule.SearchCanSubscribe(ctx, sid)
36+
if err != nil {
37+
return nil, err
38+
}
39+
detail.CanSubscribe = canSubscribe
40+
return detail, nil
41+
3042
}
3143

3244
func (i *imlCatalogueController) Search(ctx *gin.Context, keyword string) ([]*catalogue_dto.Item, []*tag_dto.Item, error) {

controller/service/iml.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -542,8 +542,9 @@ type imlAppController struct {
542542
authModule application_authorization.IAuthorizationModule `autowired:""`
543543
}
544544

545-
func (i *imlAppController) SearchCanSubscribe(ctx *gin.Context, serviceId string) ([]*service_dto.SimpleAppItem, error) {
546-
return i.module.SearchCanSubscribe(ctx, serviceId)
545+
func (i *imlAppController) SearchCanSubscribe(ctx *gin.Context, serviceId string) ([]*service_dto.SubscribeAppItem, error) {
546+
items, _, err := i.module.SearchCanSubscribe(ctx, serviceId)
547+
return items, err
547548
}
548549

549550
func (i *imlAppController) Search(ctx *gin.Context, teamId string, keyword string) ([]*service_dto.AppItem, error) {

controller/service/service.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ type IAppController interface {
4444
// SimpleApps 获取简易项目列表
4545
SimpleApps(ctx *gin.Context, keyword string) ([]*service_dto.SimpleAppItem, error)
4646
MySimpleApps(ctx *gin.Context, keyword string) ([]*service_dto.SimpleAppItem, error)
47-
SearchCanSubscribe(ctx *gin.Context, keyword string) ([]*service_dto.SimpleAppItem, error)
47+
SearchCanSubscribe(ctx *gin.Context, serviceId string) ([]*service_dto.SubscribeAppItem, error)
4848
GetApp(ctx *gin.Context, appId string) (*service_dto.App, error)
4949
DeleteApp(ctx *gin.Context, appId string) error
5050
}

module/catalogue/dto/output.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ type ServiceDetail struct {
3232
OpenAPIAddress string `json:"openapi_address"`
3333
MCPServerAddress string `json:"mcp_server_address"`
3434
MCPAccessConfig string `json:"mcp_access_config"`
35+
CanSubscribe bool `json:"can_subscribe"`
3536
}
3637

3738
type ServiceBasic struct {

module/service/dto/output.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,12 @@ type SimpleAppItem struct {
8686
Description string `json:"description"`
8787
}
8888

89+
type SubscribeAppItem struct {
90+
Id string `json:"id"`
91+
Name string `json:"name"`
92+
IsSubscribed bool `json:"is_subscribed"`
93+
}
94+
8995
type Service struct {
9096
Id string `json:"id"`
9197
Name string `json:"name"`

module/service/iml.go

Lines changed: 35 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -861,65 +861,70 @@ type imlAppModule struct {
861861
transaction store.ITransaction `autowired:""`
862862
}
863863

864-
func (i *imlAppModule) SearchCanSubscribe(ctx context.Context, serviceId string) ([]*service_dto.SimpleAppItem, error) {
864+
func (i *imlAppModule) SearchCanSubscribe(ctx context.Context, serviceId string) ([]*service_dto.SubscribeAppItem, bool, error) {
865865
apps, err := i.searchMyApps(ctx, "", "")
866866
if err != nil {
867-
return nil, err
867+
return nil, false, err
868+
}
869+
subscribes, err := i.subscribeService.ListByServices(ctx, serviceId)
870+
if err != nil {
871+
return nil, false, err
868872
}
873+
subscribeMap := utils.SliceToMapO(subscribes, func(p *subscribe.Subscribe) (string, struct{}) {
874+
return p.Application, struct{}{}
875+
}, func(s *subscribe.Subscribe) bool {
876+
return s.ApplyStatus == subscribe.ApplyStatusSubscribe
877+
})
878+
canSubscribe := false
869879
list, err := i.roleService.ListByPermit(ctx, access.SystemWorkspaceApplicationManagerAll)
870880
if err == nil && len(list) > 0 {
871-
return utils.SliceToSlice(apps, func(p *service.Service) *service_dto.SimpleAppItem {
872-
return &service_dto.SimpleAppItem{
873-
Id: p.Id,
874-
Name: p.Name,
875-
Description: p.Description,
876-
Team: auto.UUID(p.Team),
881+
return utils.SliceToSlice(apps, func(p *service.Service) *service_dto.SubscribeAppItem {
882+
_, isSubscribed := subscribeMap[p.Id]
883+
if !isSubscribed {
884+
canSubscribe = true
877885
}
878-
}), nil
886+
return &service_dto.SubscribeAppItem{
887+
Id: p.Id,
888+
Name: p.Name,
889+
IsSubscribed: isSubscribed,
890+
}
891+
}), canSubscribe, nil
879892
}
880893
list, err = i.roleService.ListByPermit(ctx, access.TeamConsumerSubscriptionSubscribe)
881894
if err != nil {
882-
return nil, nil
895+
return nil, false, nil
883896
}
884897
roleIds := utils.SliceToSlice(list, func(p *role.RoleByPermit) string {
885898
return p.Id
886899
})
887900
members, err := i.roleMemberService.ListByRoleIds(ctx, utils.UserId(ctx), roleIds...)
888901
if err != nil {
889-
return nil, err
902+
return nil, false, err
890903
}
891904
if len(members) == 0 {
892-
return nil, nil
905+
return nil, false, nil
893906
}
894-
subscribes, err := i.subscribeService.ListByServices(ctx, serviceId)
895-
if err != nil {
896-
return nil, err
897-
}
898-
subscribeMap := utils.SliceToMapO(subscribes, func(p *subscribe.Subscribe) (string, struct{}) {
899-
return p.Application, struct{}{}
900-
}, func(s *subscribe.Subscribe) bool {
901-
return s.ApplyStatus == subscribe.ApplyStatusSubscribe
902-
})
907+
903908
teamMap := utils.SliceToMapO(members, func(p *role.Member) (string, struct{}) {
904909
return role.TrimTeamTarget(p.Target), struct{}{}
905910
})
906-
result := make([]*service_dto.SimpleAppItem, 0, len(apps))
911+
result := make([]*service_dto.SubscribeAppItem, 0, len(apps))
907912
for _, app := range apps {
908913
if _, ok := teamMap[app.Team]; !ok {
909914
continue
910915
}
911-
if _, ok := subscribeMap[app.Id]; ok {
912-
continue
916+
_, isSubscribed := subscribeMap[app.Id]
917+
if !isSubscribed {
918+
canSubscribe = true
913919
}
914-
result = append(result, &service_dto.SimpleAppItem{
915-
Id: app.Id,
916-
Name: app.Name,
917-
Description: app.Description,
918-
Team: auto.UUID(app.Team),
920+
result = append(result, &service_dto.SubscribeAppItem{
921+
Id: app.Id,
922+
Name: app.Name,
923+
IsSubscribed: isSubscribed,
919924
})
920925
}
921926

922-
return result, nil
927+
return result, canSubscribe, nil
923928
}
924929

925930
func (i *imlAppModule) ExportAll(ctx context.Context) ([]*service_dto.ExportApp, error) {

module/service/module.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ type IAppModule interface {
5151
UpdateApp(ctx context.Context, appId string, input *service_dto.UpdateApp) (*service_dto.App, error)
5252
Search(ctx context.Context, teamId string, keyword string) ([]*service_dto.AppItem, error)
5353
SearchMyApps(ctx context.Context, teamId string, keyword string) ([]*service_dto.AppItem, error)
54-
SearchCanSubscribe(ctx context.Context, serviceId string) ([]*service_dto.SimpleAppItem, error)
54+
SearchCanSubscribe(ctx context.Context, serviceId string) ([]*service_dto.SubscribeAppItem, bool, error)
5555
// SimpleApps 获取简易项目列表
5656
SimpleApps(ctx context.Context, keyword string) ([]*service_dto.SimpleAppItem, error)
5757
MySimpleApps(ctx context.Context, keyword string) ([]*service_dto.SimpleAppItem, error)

0 commit comments

Comments
 (0)