From 78c7850fb2aa16583e8cf48c00cf7777a8c58d95 Mon Sep 17 00:00:00 2001 From: Adam Moussa <166072409+amoussa1229@users.noreply.github.com> Date: Thu, 16 Apr 2026 19:25:42 -0400 Subject: [PATCH] Add DashboardController with Stats endpoint - Returns total, open, notDispatched, completed work order counts --- .../Controllers/DashboardController.cs | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 Api.SeaHavenIndustries/Controllers/DashboardController.cs diff --git a/Api.SeaHavenIndustries/Controllers/DashboardController.cs b/Api.SeaHavenIndustries/Controllers/DashboardController.cs new file mode 100644 index 0000000..b548af6 --- /dev/null +++ b/Api.SeaHavenIndustries/Controllers/DashboardController.cs @@ -0,0 +1,39 @@ +using Data.SeaHavenIndustries; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; + +namespace Api.SeaHavenIndustries.Controllers +{ + [Authorize] + [ApiController] + [Route("api/[controller]")] + public class DashboardController : Controller + { + private readonly ApplicationDbContext _db; + + public DashboardController(ApplicationDbContext db) + { + _db = db; + } + + [HttpGet("Stats")] + public async Task GetStats() + { + var query = _db.workOrders.Where(w => w.istemplate != true); + + var total = await query.CountAsync(); + var open = await query.CountAsync(w => w.Status == "Open" || w.Status == "In Progress" || w.Status == "On Hold"); + var notDispatched = await query.CountAsync(w => (w.Status == "Open") && (w.AssignTo == null || w.AssignTo == "")); + var completed = await query.CountAsync(w => w.Status == "Done"); + + return Ok(new + { + total, + open, + notDispatched, + completed + }); + } + } +}