summaryrefslogtreecommitdiff
path: root/src/marlin.web/Controllers/AgentsController.cs
diff options
context:
space:
mode:
authorMelodi <62381002+Melodi17@users.noreply.github.com>2026-09-13 13:22:20 +1000
committerMelodi <62381002+Melodi17@users.noreply.github.com>2026-09-13 13:22:20 +1000
commitdf0737e55afeb5c01eb39909605970d1d3a73ffc (patch)
tree09823eaa310c60eefd2420dc305acae45c81900f /src/marlin.web/Controllers/AgentsController.cs
parentee69ce25b2fba871920260028bb10c2d6b62b26f (diff)
refactor: cleanup; feat: connection to agent
Diffstat (limited to 'src/marlin.web/Controllers/AgentsController.cs')
-rw-r--r--src/marlin.web/Controllers/AgentsController.cs89
1 files changed, 89 insertions, 0 deletions
diff --git a/src/marlin.web/Controllers/AgentsController.cs b/src/marlin.web/Controllers/AgentsController.cs
new file mode 100644
index 0000000..199acf9
--- /dev/null
+++ b/src/marlin.web/Controllers/AgentsController.cs
@@ -0,0 +1,89 @@
+namespace marlin.web.Controllers;
+
+using core.models;
+using core.util;
+using Data;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.EntityFrameworkCore;
+using Models;
+
+[Route("agents")]
+public class AgentsController(ApplicationDbContext dbContext) : Controller
+{
+ [HttpGet("list")]
+ public async Task<IActionResult> List(CancellationToken ct)
+ {
+ var items = await dbContext
+ .Agents
+ .Include(x => x.Jobs.Where(j => j.Status == JobStatus.Active))
+ .ToListAsync(ct);
+
+ return this.View(items);
+ }
+
+ [HttpGet("details/{id}")]
+ public async Task<IActionResult> Details(Guid id, CancellationToken ct)
+ {
+ var item = await dbContext.Agents
+ .Include(x => x.Jobs.Where(j => j.Status == JobStatus.Active))
+ .FirstOrDefaultAsync(x => x.Id == id, ct);
+
+ if (item == null)
+ return this.NotFound();
+
+ return this.View(item);
+ }
+
+ [HttpPost("edit/{id}")]
+ public async Task<IActionResult> Edit(Guid id, Agent agent, CancellationToken ct)
+ {
+ var item = await dbContext.Agents
+ .FirstOrDefaultAsync(x => x.Id == id, ct);
+
+ if (item == null)
+ return this.NotFound();
+
+ item.Name = agent.Name;
+ item.MaxConcurrentJobs = agent.MaxConcurrentJobs;
+
+ await dbContext.SaveChangesAsync(ct);
+
+ return this.RedirectToAction("Details", new { id });
+ }
+
+ [HttpPost("details/{id}/regenerate-token")]
+ public async Task<IActionResult> RegenerateToken(Guid id, CancellationToken ct)
+ {
+ var item = await dbContext.Agents
+ .FirstOrDefaultAsync(x => x.Id == id, ct);
+
+ if (item == null)
+ return this.NotFound();
+
+ item.AuthToken = SecureTokenGenerator.CreateAgentToken();
+
+ await dbContext.SaveChangesAsync(ct);
+
+ return this.RedirectToAction("Details", new { id });
+ }
+
+ [HttpGet("create")]
+ public IActionResult Create()
+ {
+ return this.View();
+ }
+
+ [HttpPost("create")]
+ public async Task<IActionResult> CreatePost(Agent agent, CancellationToken ct)
+ {
+ agent.Id = Guid.Empty;
+ agent.AuthToken = SecureTokenGenerator.CreateAgentToken();
+ agent.LastSeen = DateTime.UtcNow;
+ agent.Capabilities = new CapabilitySet();
+
+ await dbContext.Agents.AddAsync(agent, ct);
+ await dbContext.SaveChangesAsync(ct);
+
+ return this.RedirectToAction("Details", new { id = agent.Id });
+ }
+} \ No newline at end of file