From ccedea6e6783592c1a2fc7f43cbc075a1a8217e8 Mon Sep 17 00:00:00 2001 From: AJ Isaacs Date: Mon, 20 Apr 2026 20:32:12 -0400 Subject: [PATCH] feat(api): add Health and Audit controllers Co-Authored-By: Claude Opus 4.6 --- MoneyMap/Controllers/AuditController.cs | 26 ++++++++++++++++++++++++ MoneyMap/Controllers/HealthController.cs | 23 +++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 MoneyMap/Controllers/AuditController.cs create mode 100644 MoneyMap/Controllers/HealthController.cs diff --git a/MoneyMap/Controllers/AuditController.cs b/MoneyMap/Controllers/AuditController.cs new file mode 100644 index 0000000..936afc8 --- /dev/null +++ b/MoneyMap/Controllers/AuditController.cs @@ -0,0 +1,26 @@ +using Microsoft.AspNetCore.Mvc; +using MoneyMap.Services; + +namespace MoneyMap.Controllers; + +[ApiController] +[Route("api/[controller]")] +public class AuditController : ControllerBase +{ + private readonly IFinancialAuditService _auditService; + + public AuditController(IFinancialAuditService auditService) => _auditService = auditService; + + [HttpGet] + public async Task Get( + [FromQuery] DateTime? startDate, + [FromQuery] DateTime? endDate, + [FromQuery] bool includeTransactions = false) + { + var end = endDate ?? DateTime.Today; + var start = startDate ?? end.AddDays(-90); + + var result = await _auditService.GenerateAuditAsync(start, end, includeTransactions); + return Ok(result); + } +} diff --git a/MoneyMap/Controllers/HealthController.cs b/MoneyMap/Controllers/HealthController.cs new file mode 100644 index 0000000..f22b541 --- /dev/null +++ b/MoneyMap/Controllers/HealthController.cs @@ -0,0 +1,23 @@ +using Microsoft.AspNetCore.Mvc; +using MoneyMap.Data; + +namespace MoneyMap.Controllers; + +[ApiController] +[Route("api/[controller]")] +public class HealthController : ControllerBase +{ + private readonly MoneyMapContext _db; + + public HealthController(MoneyMapContext db) => _db = db; + + [HttpGet] + public async Task Get() + { + var canConnect = await _db.Database.CanConnectAsync(); + if (!canConnect) + return StatusCode(503, new { status = "unhealthy", reason = "database unreachable" }); + + return Ok(new { status = "healthy" }); + } +}