mirror of
https://github.com/Sea-Haven-Industries/shoc-backend.git
synced 2026-09-30 11:53:12 +00:00
Add DashboardController with Stats endpoint
- Returns total, open, notDispatched, completed work order counts
This commit is contained in:
parent
8959efc06b
commit
78c7850fb2
1 changed files with 39 additions and 0 deletions
39
Api.SeaHavenIndustries/Controllers/DashboardController.cs
Normal file
39
Api.SeaHavenIndustries/Controllers/DashboardController.cs
Normal file
|
|
@ -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<IActionResult> 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
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue