Sistema de Notificaciones y Baja One-Click
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using MotoresArgentinosV2.Core.Interfaces;
|
||||
|
||||
namespace MotoresArgentinosV2.API.Controllers;
|
||||
|
||||
/// <summary>
|
||||
/// Controlador PÚBLICO (sin autenticación) para gestionar la baja de correos.
|
||||
/// El token del enlace garantiza que no se puede dar de baja a otro usuario.
|
||||
/// </summary>
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
public class UnsubscribeController : ControllerBase
|
||||
{
|
||||
private readonly INotificationPreferenceService _prefService;
|
||||
private readonly IConfiguration _config;
|
||||
|
||||
public UnsubscribeController(
|
||||
INotificationPreferenceService prefService,
|
||||
IConfiguration config)
|
||||
{
|
||||
_prefService = prefService;
|
||||
_config = config;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Procesa la baja one-click desde el enlace del correo.
|
||||
/// GET api/unsubscribe?token=xxxxx
|
||||
/// Redirige al frontend con el resultado para mostrar una página amigable.
|
||||
/// </summary>
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> Unsubscribe([FromQuery] string token)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(token))
|
||||
return BadRequest(new { success = false, message = "Token inválido o faltante." });
|
||||
|
||||
var (success, categoryLabel) = await _prefService.UnsubscribeAsync(token);
|
||||
|
||||
if (success)
|
||||
{
|
||||
return Ok(new { success = true, category = categoryLabel });
|
||||
}
|
||||
|
||||
return BadRequest(new { success = false, message = "El enlace de baja ha expirado o no es válido." });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user