mirror of
https://github.com/Sea-Haven-Industries/proposal-system.git
synced 2026-10-05 04:52:02 +00:00
- API-M2: Add comment for fail-loud auth config guard (already implemented) - API-M5: Add FluentValidation validators for VendorProposal, GeneratedPdf, and SimilarReference DTOs; move request records to Application DTOs - API-M7: Add AsNoTracking() to all read-only queries in ProposalService, LineItemService, AdminController, UsersController, FilesController - API-M9: Log stderr from dev PDF generation instead of returning to client - API-M10: Return generic "Authentication service unavailable" in auth callbacks instead of leaking Cognito/DevMode configuration state - API-M12: Enrich audit logging with before/after values for status changes, proposal edits, and line item operations using structured JSON - API-M13: Log previous role alongside new role on user role changes in both UsersController and Cognito-synced role updates in AuthController
56 lines
1.9 KiB
C#
56 lines
1.9 KiB
C#
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using ProposalSystem.Application.DTOs;
|
|
using ProposalSystem.Domain.Entities;
|
|
using ProposalSystem.Infrastructure.Data;
|
|
|
|
namespace ProposalSystem.Api.Controllers;
|
|
|
|
[ApiController]
|
|
[Route("api/admin")]
|
|
[Authorize(Roles = "admins,sysadmins")]
|
|
public class AdminController : ControllerBase
|
|
{
|
|
private readonly ProposalDbContext _db;
|
|
|
|
public AdminController(ProposalDbContext db)
|
|
{
|
|
_db = db;
|
|
}
|
|
|
|
[HttpGet("dashboard")]
|
|
public async Task<ActionResult<DashboardResponse>> GetDashboard(CancellationToken ct)
|
|
{
|
|
// Fix: API-M7 — AsNoTracking on read-only dashboard queries
|
|
var pendingCount = await _db.Proposals
|
|
.AsNoTracking()
|
|
.CountAsync(p => p.Status == ProposalStatus.InReview, ct);
|
|
|
|
var weekStart = DateTime.UtcNow.AddDays(-7);
|
|
var approvedThisWeek = await _db.Proposals
|
|
.AsNoTracking()
|
|
.CountAsync(p => p.ApprovedAt >= weekStart, ct);
|
|
|
|
var approvedCount = await _db.Proposals
|
|
.AsNoTracking()
|
|
.CountAsync(p => p.ApprovedAt.HasValue, ct);
|
|
|
|
double avgTurnaround = 0;
|
|
if (approvedCount > 0)
|
|
{
|
|
var recentApproved = await _db.Proposals
|
|
.AsNoTracking()
|
|
.Where(p => p.ApprovedAt.HasValue)
|
|
.OrderByDescending(p => p.ApprovedAt)
|
|
.Take(200)
|
|
.Select(p => new { p.ApprovedAt, p.SubmittedAt })
|
|
.ToListAsync(ct);
|
|
avgTurnaround = recentApproved.Average(p => (p.ApprovedAt!.Value - p.SubmittedAt).TotalHours);
|
|
}
|
|
|
|
var totalProposals = await _db.Proposals.AsNoTracking().CountAsync(ct);
|
|
|
|
return Ok(new DashboardResponse(pendingCount, approvedThisWeek, avgTurnaround, totalProposals));
|
|
}
|
|
}
|