MCPcopy Index your code
hub / github.com/APIParkLab/APIPark / SearchMyApps

Method SearchMyApps

module/service/iml.go:1294–1360  ·  view source on GitHub ↗
(ctx context.Context, teamId string, keyword string)

Source from the content-addressed store, hash-verified

1292}
1293
1294func (i *imlAppModule) SearchMyApps(ctx context.Context, teamId string, keyword string) ([]*service_dto.AppItem, error) {
1295 services, err := i.searchMyApps(ctx, teamId, keyword)
1296 if err != nil {
1297 return nil, err
1298 }
1299 serviceIds := utils.SliceToSlice(services, func(p *service.Service) string {
1300 return p.Id
1301 })
1302
1303 subscribers, err := i.subscribeService.SubscriptionsByApplication(ctx, serviceIds...)
1304 if err != nil {
1305 return nil, err
1306 }
1307 authMap, err := i.authService.CountByApp(ctx, serviceIds...)
1308 if err != nil {
1309 return nil, err
1310 }
1311
1312 subscribeCount := map[string]int64{}
1313 subscribeVerifyCount := map[string]int64{}
1314 verifyTmp := map[string]struct{}{}
1315 subscribeTmp := map[string]struct{}{}
1316 for _, s := range subscribers {
1317 key := fmt.Sprintf("%s-%s", s.Service, s.Application)
1318 switch s.ApplyStatus {
1319 case subscribe.ApplyStatusSubscribe:
1320 if _, ok := subscribeTmp[key]; !ok {
1321 subscribeTmp[key] = struct{}{}
1322 subscribeCount[s.Application]++
1323 }
1324 case subscribe.ApplyStatusReview:
1325 if _, ok := verifyTmp[key]; !ok {
1326 verifyTmp[key] = struct{}{}
1327 subscribeVerifyCount[s.Application]++
1328 }
1329 default:
1330
1331 }
1332 }
1333 items := make([]*service_dto.AppItem, 0, len(services))
1334 for _, model := range services {
1335 subscribeNum := subscribeCount[model.Id]
1336 verifyNum := subscribeVerifyCount[model.Id]
1337 items = append(items, &service_dto.AppItem{
1338 Id: model.Id,
1339 Name: model.Name,
1340 Description: model.Description,
1341 CreateTime: auto.TimeLabel(model.CreateTime),
1342 UpdateTime: auto.TimeLabel(model.UpdateTime),
1343 Team: auto.UUID(model.Team),
1344 SubscribeNum: subscribeNum,
1345 SubscribeVerifyNum: verifyNum,
1346 CanDelete: subscribeNum == 0,
1347 AuthNum: authMap[model.Id],
1348 })
1349 }
1350 sort.Slice(items, func(i, j int) bool {
1351 if items[i].SubscribeNum != items[j].SubscribeNum {

Callers

nothing calls this directly

Calls 3

searchMyAppsMethod · 0.95
CountByAppMethod · 0.65

Tested by

no test coverage detected