(ctx context.Context, teamID string, keyword string)
| 594 | } |
| 595 | |
| 596 | func (i *imlServiceModule) Search(ctx context.Context, teamID string, keyword string) ([]*service_dto.ServiceItem, error) { |
| 597 | var list []*service.Service |
| 598 | var err error |
| 599 | if teamID != "" { |
| 600 | _, err = i.teamService.Get(ctx, teamID) |
| 601 | if err != nil { |
| 602 | return nil, err |
| 603 | } |
| 604 | list, err = i.serviceService.Search(ctx, keyword, map[string]interface{}{"team": teamID, "as_server": true}, "create_at desc") |
| 605 | } else { |
| 606 | list, err = i.serviceService.Search(ctx, keyword, map[string]interface{}{"as_server": true}, "create_at desc") |
| 607 | } |
| 608 | if err != nil { |
| 609 | return nil, err |
| 610 | } |
| 611 | serviceIds := utils.SliceToSlice(list, func(s *service.Service) string { |
| 612 | return s.Id |
| 613 | }) |
| 614 | overviewMap, err := i.serviceOverviewService.Map(ctx, serviceIds...) |
| 615 | if err != nil { |
| 616 | return nil, err |
| 617 | } |
| 618 | items := make([]*service_dto.ServiceItem, 0, len(list)) |
| 619 | for _, model := range list { |
| 620 | item := toServiceItem(model) |
| 621 | if v, ok := overviewMap[model.Id]; ok { |
| 622 | item.ApiNum = v.ApiCount |
| 623 | item.CanDelete = v.ApiCount == 0 |
| 624 | } |
| 625 | |
| 626 | items = append(items, item) |
| 627 | } |
| 628 | return items, nil |
| 629 | } |
| 630 | |
| 631 | func toServiceItem(model *service.Service) *service_dto.ServiceItem { |
| 632 | item := &service_dto.ServiceItem{ |
nothing calls this directly
no test coverage detected