Skip to content

Commit

Permalink
469941: Sort deployments by teamId
Browse files Browse the repository at this point in the history
If teamId's are provided via the avouriteTeamIds query array, then sort
by services that are owned by these teams
  • Loading branch information
feedmypixel committed Jan 22, 2025
1 parent 6373dc5 commit 661bf58
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Defra.Cdp.Backend.Api/Endpoints/DeploymentsEndpointV2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public static void MapDeploymentsEndpointV2(this IEndpointRouteBuilder app)

// GET /v2/deployments or with query params GET /v2/deployments?environment=dev&service=forms-runner&user=jeff&status=running&page=1&offset=0&size=50
private static async Task<IResult> FindLatestDeployments(IDeploymentsServiceV2 deploymentsService,
[FromQuery(Name = "favouriteTeamIds")] string[]? favouriteTeamIds,
[FromQuery(Name = "environment")] string? environment,
[FromQuery(Name = "service")] string? service,
[FromQuery(Name = "user")] string? user,
Expand All @@ -35,6 +36,7 @@ private static async Task<IResult> FindLatestDeployments(IDeploymentsServiceV2 d
CancellationToken cancellationToken)
{
var deploymentsPage = await deploymentsService.FindLatest(
favouriteTeamIds,
environment,
service,
user,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public interface IDeploymentsServiceV2
Task<bool> UpdateDeploymentStatus(string lambdaId, string eventName, string reason, CancellationToken ct);

Task<Paginated<DeploymentV2>> FindLatest(
string[]? favouriteTeamIds,
string? environment,
string? service,
string? user,
Expand Down Expand Up @@ -181,7 +182,8 @@ public async Task<List<DeploymentV2>> FindWhatsRunningWhere(string serviceName,
.ToListAsync(ct);
}

public async Task<Paginated<DeploymentV2>> FindLatest(string? environment, string? service, string? user,
public async Task<Paginated<DeploymentV2>> FindLatest(string[]? favouriteTeamIds, string? environment,
string? service, string? user,
string? status,
string? team,
int offset = 0,
Expand Down Expand Up @@ -237,6 +239,18 @@ public async Task<Paginated<DeploymentV2>> FindLatest(string? environment, strin
.SortByDescending(d => d.Created)
.ToListAsync(ct);

if (favouriteTeamIds?.Length > 0)
{
var repos = (await Task.WhenAll(favouriteTeamIds.Select(teamId =>
_repositoryService.FindRepositoriesByTeamId(teamId, true, ct))))
.SelectMany(r => r)
.ToList();

var servicesOwnedByTeam = repos.Select(r => r.Id);

deployments = deployments.OrderByDescending(d => servicesOwnedByTeam.Contains(d.Service)).ToList();
}

var totalDeployments = await Collection.CountDocumentsAsync(filter, cancellationToken: ct);

var totalPages = Math.Max(1, (int)Math.Ceiling((double)totalDeployments / size));
Expand Down

0 comments on commit 661bf58

Please sign in to comment.