List returns all repositories with host counts and host details.
(ctx context.Context, params RepoListParams)
| 30 | |
| 31 | // List returns all repositories with host counts and host details. |
| 32 | func (s *RepositoriesStore) List(ctx context.Context, params RepoListParams) ([]RepositoryWithHosts, error) { |
| 33 | d := s.db.DB(ctx) |
| 34 | arg := db.ListRepositoriesParams{} |
| 35 | if params.HostID != "" { |
| 36 | arg.HostID = ¶ms.HostID |
| 37 | } |
| 38 | if params.Search != "" { |
| 39 | arg.Search = ¶ms.Search |
| 40 | } |
| 41 | if params.Status != "" { |
| 42 | arg.Status = ¶ms.Status |
| 43 | } |
| 44 | if params.Type != "" { |
| 45 | arg.Type = ¶ms.Type |
| 46 | } |
| 47 | |
| 48 | repos, err := d.Queries.ListRepositories(ctx, arg) |
| 49 | if err != nil { |
| 50 | return nil, err |
| 51 | } |
| 52 | if len(repos) == 0 { |
| 53 | return []RepositoryWithHosts{}, nil |
| 54 | } |
| 55 | |
| 56 | ids := make([]string, len(repos)) |
| 57 | for i := range repos { |
| 58 | ids[i] = repos[i].ID |
| 59 | } |
| 60 | |
| 61 | hostRows, err := d.Queries.GetHostCountsForRepos(ctx, ids) |
| 62 | if err != nil { |
| 63 | return nil, err |
| 64 | } |
| 65 | |
| 66 | hostsByRepo := make(map[string][]HostRepoHost) |
| 67 | for _, r := range hostRows { |
| 68 | h := HostRepoHost{ |
| 69 | ID: r.ID, |
| 70 | FriendlyName: r.FriendlyName, |
| 71 | Status: r.Status, |
| 72 | IsEnabled: r.IsEnabled, |
| 73 | } |
| 74 | if r.LastChecked.Valid { |
| 75 | t := r.LastChecked.Time.Format("2006-01-02T15:04:05Z07:00") |
| 76 | h.LastChecked = &t |
| 77 | } |
| 78 | hostsByRepo[r.RepositoryID] = append(hostsByRepo[r.RepositoryID], h) |
| 79 | } |
| 80 | |
| 81 | out := make([]RepositoryWithHosts, len(repos)) |
| 82 | for i := range repos { |
| 83 | rid := repos[i].ID |
| 84 | hosts := hostsByRepo[rid] |
| 85 | hostCount := len(hosts) |
| 86 | enabledCount, activeCount := 0, 0 |
| 87 | for _, h := range hosts { |
| 88 | if h.IsEnabled { |
| 89 | enabledCount++ |
nothing calls this directly
no test coverage detected