Sistema de Notificaciones y Baja One-Click

This commit is contained in:
2026-03-12 13:52:33 -03:00
parent f1a9bb9099
commit 96fca4d9c7
21 changed files with 1384 additions and 79 deletions

View File

@@ -2,6 +2,7 @@ using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using MotoresArgentinosV2.Core.DTOs;
using MotoresArgentinosV2.Core.Entities;
using MotoresArgentinosV2.Core.Interfaces;
using MotoresArgentinosV2.Infrastructure.Data;
using Microsoft.AspNetCore.Authorization;
using System.Security.Claims;
@@ -14,10 +15,14 @@ namespace MotoresArgentinosV2.API.Controllers;
public class ProfileController : ControllerBase
{
private readonly MotoresV2DbContext _context;
private readonly INotificationPreferenceService _notifPrefService;
public ProfileController(MotoresV2DbContext context)
public ProfileController(
MotoresV2DbContext context,
INotificationPreferenceService notifPrefService)
{
_context = context;
_notifPrefService = notifPrefService;
}
[HttpGet]
@@ -71,4 +76,43 @@ public class ProfileController : ControllerBase
return Ok(new { message = "Perfil actualizado con éxito." });
}
// ─── Preferencias de Notificación ────────────────────────────────────────
/// <summary>
/// Obtiene las preferencias de notificación del usuario autenticado.
/// GET api/profile/notification-preferences
/// </summary>
[HttpGet("notification-preferences")]
public async Task<IActionResult> GetNotificationPreferences()
{
var userId = int.Parse(User.FindFirst(ClaimTypes.NameIdentifier)?.Value ?? "0");
var prefs = await _notifPrefService.GetPreferencesAsync(userId);
return Ok(prefs);
}
/// <summary>
/// Actualiza las preferencias de notificación del usuario autenticado.
/// PUT api/profile/notification-preferences
/// </summary>
[HttpPut("notification-preferences")]
public async Task<IActionResult> UpdateNotificationPreferences(
[FromBody] UpdateNotificationPreferencesDto dto)
{
var userId = int.Parse(User.FindFirst(ClaimTypes.NameIdentifier)?.Value ?? "0");
await _notifPrefService.UpdatePreferencesAsync(userId, dto);
// Registramos en auditoría
_context.AuditLogs.Add(new AuditLog
{
Action = "NOTIFICATION_PREFS_UPDATED",
Entity = "User",
EntityID = userId,
UserID = userId,
Details = "Usuario actualizó sus preferencias de notificación."
});
await _context.SaveChangesAsync();
return Ok(new { message = "Preferencias actualizadas con éxito." });
}
}