(ctx context.Context, teamId string, keyword string)
| 1137 | } |
| 1138 | |
| 1139 | func (i *imlAppModule) Search(ctx context.Context, teamId string, keyword string) ([]*service_dto.AppItem, error) { |
| 1140 | var services []*service.Service |
| 1141 | var err error |
| 1142 | if teamId != "" { |
| 1143 | _, err = i.teamService.Get(ctx, teamId) |
| 1144 | if err != nil { |
| 1145 | return nil, err |
| 1146 | } |
| 1147 | services, err = i.serviceService.Search(ctx, keyword, map[string]interface{}{"team": teamId, "as_app": true}, "update_at desc") |
| 1148 | } else { |
| 1149 | services, err = i.serviceService.Search(ctx, keyword, map[string]interface{}{"as_app": true}, "update_at desc") |
| 1150 | } |
| 1151 | if err != nil { |
| 1152 | return nil, err |
| 1153 | } |
| 1154 | |
| 1155 | serviceIds := utils.SliceToSlice(services, func(p *service.Service) string { |
| 1156 | return p.Id |
| 1157 | }) |
| 1158 | |
| 1159 | subscribers, err := i.subscribeService.SubscriptionsByApplication(ctx, serviceIds...) |
| 1160 | if err != nil { |
| 1161 | return nil, err |
| 1162 | } |
| 1163 | |
| 1164 | subscribeCount := map[string]int64{} |
| 1165 | subscribeVerifyCount := map[string]int64{} |
| 1166 | verifyTmp := map[string]struct{}{} |
| 1167 | subscribeTmp := map[string]struct{}{} |
| 1168 | for _, s := range subscribers { |
| 1169 | key := fmt.Sprintf("%s-%s", s.Service, s.Application) |
| 1170 | switch s.ApplyStatus { |
| 1171 | case subscribe.ApplyStatusSubscribe: |
| 1172 | if _, ok := subscribeTmp[key]; !ok { |
| 1173 | subscribeTmp[key] = struct{}{} |
| 1174 | subscribeCount[s.Application]++ |
| 1175 | } |
| 1176 | case subscribe.ApplyStatusReview: |
| 1177 | if _, ok := verifyTmp[key]; !ok { |
| 1178 | verifyTmp[key] = struct{}{} |
| 1179 | subscribeVerifyCount[s.Application]++ |
| 1180 | } |
| 1181 | default: |
| 1182 | |
| 1183 | } |
| 1184 | } |
| 1185 | authMap, err := i.authService.CountByApp(ctx, serviceIds...) |
| 1186 | if err != nil { |
| 1187 | return nil, err |
| 1188 | } |
| 1189 | items := make([]*service_dto.AppItem, 0, len(services)) |
| 1190 | for _, model := range services { |
| 1191 | subscribeNum := subscribeCount[model.Id] |
| 1192 | verifyNum := subscribeVerifyCount[model.Id] |
| 1193 | items = append(items, &service_dto.AppItem{ |
| 1194 | Id: model.Id, |
| 1195 | Name: model.Name, |
| 1196 | Description: model.Description, |
nothing calls this directly
no test coverage detected