aboutsummaryrefslogtreecommitdiff
path: root/src/Enmarcha.Backend/Controllers/Backoffice
diff options
context:
space:
mode:
authorAriel Costas Guerrero <ariel@costas.dev>2026-04-02 12:38:10 +0200
committerAriel Costas Guerrero <ariel@costas.dev>2026-04-02 12:45:33 +0200
commit1b4f4a674ac533c0b51260ba35ab91dd2cf9486d (patch)
tree9fdaf418bef86c51737bcf203483089c9e2b908b /src/Enmarcha.Backend/Controllers/Backoffice
parent749e04d6fc2304bb29920db297d1fa4d73b57648 (diff)
Basic push notification system for service alerts
Co-authored-by: Copilot <copilot@github.com>
Diffstat (limited to 'src/Enmarcha.Backend/Controllers/Backoffice')
-rw-r--r--src/Enmarcha.Backend/Controllers/Backoffice/AlertsController.cs21
1 files changed, 20 insertions, 1 deletions
diff --git a/src/Enmarcha.Backend/Controllers/Backoffice/AlertsController.cs b/src/Enmarcha.Backend/Controllers/Backoffice/AlertsController.cs
index 4e83abc..3fa499e 100644
--- a/src/Enmarcha.Backend/Controllers/Backoffice/AlertsController.cs
+++ b/src/Enmarcha.Backend/Controllers/Backoffice/AlertsController.cs
@@ -1,4 +1,5 @@
using Enmarcha.Backend.Data;
+using Enmarcha.Backend.Services;
using Enmarcha.Backend.ViewModels;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
@@ -8,7 +9,11 @@ namespace Enmarcha.Backend.Controllers.Backoffice;
[Route("backoffice/alerts")]
[Authorize(AuthenticationSchemes = "Backoffice")]
-public class AlertsController(AppDbContext db) : Controller
+public class AlertsController(
+ AppDbContext db,
+ IPushNotificationService pushService,
+ ILogger<AlertsController> logger
+) : Controller
{
[HttpGet("")]
public async Task<IActionResult> Index()
@@ -28,6 +33,7 @@ public class AlertsController(AppDbContext db) : Controller
{
if (!ModelState.IsValid)
{
+ logger.LogWarning("Invalid model state when creating alert: {Errors}", ModelState.Values.SelectMany(v => v.Errors).Select(e => e.ErrorMessage));
return View("Edit", model);
}
@@ -50,6 +56,7 @@ public class AlertsController(AppDbContext db) : Controller
{
if (!ModelState.IsValid)
{
+ logger.LogWarning("Invalid model state when editing alert {Id}: {Errors}", id, ModelState.Values.SelectMany(v => v.Errors).Select(e => e.ErrorMessage));
return View("Edit", model);
}
@@ -80,4 +87,16 @@ public class AlertsController(AppDbContext db) : Controller
await db.SaveChangesAsync();
return RedirectToAction(nameof(Index));
}
+
+ [HttpPost("{id}/push")]
+ [ValidateAntiForgeryToken]
+ public async Task<IActionResult> SendPush(string id)
+ {
+ var alert = await db.ServiceAlerts.FindAsync(id);
+ if (alert is null) return NotFound();
+
+ await pushService.SendAlertAsync(alert);
+ TempData["SuccessMessage"] = $"Notificación enviada (v{alert.Version})";
+ return RedirectToAction(nameof(Index));
+ }
}