diff options
Diffstat (limited to 'src/marlin.web/Controllers/JobsController.cs')
| -rw-r--r-- | src/marlin.web/Controllers/JobsController.cs | 35 |
1 files changed, 24 insertions, 11 deletions
diff --git a/src/marlin.web/Controllers/JobsController.cs b/src/marlin.web/Controllers/JobsController.cs index c86cb2d..552b56c 100644 --- a/src/marlin.web/Controllers/JobsController.cs +++ b/src/marlin.web/Controllers/JobsController.cs @@ -4,25 +4,29 @@ using core.models; using Data; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; +using Models; using Util; [Route("jobs")] public class JobsController(ApplicationDbContext dbContext) : Controller { - // list jobs (pending, active, cancelled, success, failed), filter to vcs, filter to recipe - public record JobListFilter(JobStatus? Status = null, Guid? Vcs = null, string? Ref = null, string? Recipe = null); - + public record JobListFilter(JobStatus? Status = null, Guid? Vcs = null, Guid? Branch = null, string? Recipe = null, Guid? Agent = null); + [HttpGet("list")] public async Task<IActionResult> List([FromQuery] JobListFilter filter, CancellationToken ct) { - var results = await dbContext.Jobs + var results = await dbContext + .Jobs .WhereIf(filter.Status != null, x => x.Status == filter.Status) .WhereIf(filter.Vcs != null, x => x.SourceId == filter.Vcs) - .WhereIf(filter.Ref != null, x => x.Ref == filter.Ref) + .WhereIf(filter.Branch != null, x => x.BranchId == filter.Branch) .WhereIf(filter.Recipe != null, x => x.Recipe == filter.Recipe) + .WhereIf(filter.Agent != null, x => x.AgentId == filter.Agent) .OrderByDescending(x => x.CreatedAt) - + + .Include(x => x.Commit) + .Include(x => x.Branch) .Include(x => x.Source) .Include(x => x.Agent) .ToListAsync(ct); @@ -40,25 +44,34 @@ public class JobsController(ApplicationDbContext dbContext) : Controller [HttpGet("spawn")] public async Task<IActionResult> Spawn(CancellationToken ct) { - var sources = await dbContext.Sources + var sources = await dbContext + .Sources .Include(x => x.Branches) .ThenInclude(x => x.Commit) + .ThenInclude(x => x.WorkflowSnapshot) .ToListAsync(ct); var details = new JobSpawnDetails(sources); return this.View(details); } - public record JobSpawnRequest(Guid Vcs, string Ref, string Commit, string Recipe); + public record JobSpawnRequest(Guid Vcs, Guid Branch, string Recipe); [HttpPost("spawn")] public async Task<IActionResult> SpawnPost(JobSpawnRequest request, CancellationToken ct) { + var branch = await dbContext + .SourceBranches + .FirstOrDefaultAsync(x => x.Id == request.Branch, ct); + + if (branch == null) + return this.NotFound(); + Job job = new() { - SourceId = request.Vcs, - Ref = request.Ref, - Commit = request.Commit, + SourceId = branch.SourceId, + BranchId = branch.Id, + CommitId = branch.CommitId, Recipe = request.Recipe, CreatedAt = DateTime.UtcNow, |
