(ctx context.Context, appId string, keyword string)
| 95 | } |
| 96 | |
| 97 | func (i *imlSubscribeModule) SearchSubscriptions(ctx context.Context, appId string, keyword string) ([]*subscribe_dto.SubscriptionItem, error) { |
| 98 | info, err := i.serviceService.Get(ctx, appId) |
| 99 | if err != nil { |
| 100 | return nil, fmt.Errorf("get application error: %w", err) |
| 101 | } |
| 102 | if !info.AsApp { |
| 103 | return nil, fmt.Errorf("service %s is not an application", appId) |
| 104 | } |
| 105 | |
| 106 | // 获取当前订阅服务列表 |
| 107 | subscriptions, err := i.subscribeService.MySubscribeServices(ctx, appId, nil) |
| 108 | if err != nil { |
| 109 | return nil, err |
| 110 | } |
| 111 | serviceIds := utils.SliceToSlice(subscriptions, func(s *subscribe.Subscribe) string { |
| 112 | return s.Service |
| 113 | }) |
| 114 | services, err := i.serviceService.List(ctx, serviceIds...) |
| 115 | if err != nil { |
| 116 | return nil, fmt.Errorf("search service error: %w", err) |
| 117 | } |
| 118 | serviceMap := utils.SliceToMapArray(services, func(s *service.Service) string { |
| 119 | return s.Id |
| 120 | }) |
| 121 | |
| 122 | return utils.SliceToSlice(subscriptions, func(s *subscribe.Subscribe) *subscribe_dto.SubscriptionItem { |
| 123 | return &subscribe_dto.SubscriptionItem{ |
| 124 | Id: s.Id, |
| 125 | ApplyStatus: s.ApplyStatus, |
| 126 | Service: auto.UUID(s.Service), |
| 127 | Team: auto.UUID(info.Team), |
| 128 | From: s.From, |
| 129 | CreateTime: auto.TimeLabel(s.CreateAt), |
| 130 | } |
| 131 | }, func(s *subscribe.Subscribe) bool { |
| 132 | _, ok := serviceMap[s.Service] |
| 133 | if !ok { |
| 134 | return false |
| 135 | } |
| 136 | if s.ApplyStatus != subscribe.ApplyStatusSubscribe && s.ApplyStatus != subscribe.ApplyStatusReview { |
| 137 | return false |
| 138 | } |
| 139 | return true |
| 140 | }), nil |
| 141 | } |
| 142 | |
| 143 | func (i *imlSubscribeModule) RevokeSubscription(ctx context.Context, pid string, uuid string) error { |
| 144 | _, err := i.serviceService.Get(ctx, pid) |
nothing calls this directly
no test coverage detected