| 192 | } |
| 193 | |
| 194 | func (m *imlTeamModule) MySimpleTeams(ctx context.Context, keyword string) ([]*team_dto.SimpleTeam, error) { |
| 195 | userID := utils.UserId(ctx) |
| 196 | memberMap, err := m.teamMemberService.FilterMembersForUser(ctx, userID) |
| 197 | if err != nil { |
| 198 | return nil, err |
| 199 | } |
| 200 | teamIDs, ok := memberMap[userID] |
| 201 | if !ok || len(teamIDs) == 0 { |
| 202 | return make([]*team_dto.SimpleTeam, 0), nil |
| 203 | } |
| 204 | list, err := m.teamService.Search(ctx, keyword, map[string]interface{}{ |
| 205 | "uuid": teamIDs, |
| 206 | }) |
| 207 | if err != nil { |
| 208 | return nil, err |
| 209 | } |
| 210 | |
| 211 | projects, err := m.serviceService.Search(ctx, "", map[string]interface{}{ |
| 212 | "team": teamIDs, |
| 213 | }) |
| 214 | projectCount := make(map[string]int64) |
| 215 | appCount := make(map[string]int64) |
| 216 | for _, p := range projects { |
| 217 | if p.AsServer { |
| 218 | if _, ok := projectCount[p.Team]; !ok { |
| 219 | projectCount[p.Team] = 0 |
| 220 | } |
| 221 | projectCount[p.Team]++ |
| 222 | } |
| 223 | if p.AsApp { |
| 224 | if _, ok := appCount[p.Team]; !ok { |
| 225 | appCount[p.Team] = 0 |
| 226 | } |
| 227 | appCount[p.Team]++ |
| 228 | } |
| 229 | } |
| 230 | |
| 231 | outList := utils.SliceToSlice(list, func(s *team.Team) *team_dto.SimpleTeam { |
| 232 | return &team_dto.SimpleTeam{ |
| 233 | Id: s.Id, |
| 234 | Name: s.Name, |
| 235 | Description: s.Description, |
| 236 | ServiceNum: projectCount[s.Id], |
| 237 | AppNum: appCount[s.Id], |
| 238 | } |
| 239 | }) |
| 240 | return outList, nil |
| 241 | } |
| 242 | |
| 243 | func (m *imlTeamModule) AddMember(ctx context.Context, id string, uuids ...string) error { |
| 244 | _, err := m.teamService.Get(ctx, id) |