diff --git a/Controllers/BillingController.cs b/Controllers/BillingController.cs index 13b7964..d0315fc 100644 --- a/Controllers/BillingController.cs +++ b/Controllers/BillingController.cs @@ -10,7 +10,7 @@ namespace line_gestao_api.Controllers { [ApiController] [Route("api/[controller]")] - [Authorize] + [Authorize(Roles = "admin")] public class BillingController : ControllerBase { private readonly AppDbContext _db; diff --git a/Controllers/ChipsVirgensController.cs b/Controllers/ChipsVirgensController.cs index 1f18b17..62b88ac 100644 --- a/Controllers/ChipsVirgensController.cs +++ b/Controllers/ChipsVirgensController.cs @@ -11,7 +11,7 @@ namespace line_gestao_api.Controllers { [ApiController] [Route("api/chips-virgens")] - [Authorize] + [Authorize(Roles = "admin")] public class ChipsVirgensController : ControllerBase { private readonly AppDbContext _db; diff --git a/Controllers/ControleRecebidosController.cs b/Controllers/ControleRecebidosController.cs index e0e2a75..918a73b 100644 --- a/Controllers/ControleRecebidosController.cs +++ b/Controllers/ControleRecebidosController.cs @@ -11,7 +11,7 @@ namespace line_gestao_api.Controllers { [ApiController] [Route("api/controle-recebidos")] - [Authorize] + [Authorize(Roles = "admin")] public class ControleRecebidosController : ControllerBase { private readonly AppDbContext _db; diff --git a/Controllers/NotificationsController.cs b/Controllers/NotificationsController.cs index d580e13..a9f2317 100644 --- a/Controllers/NotificationsController.cs +++ b/Controllers/NotificationsController.cs @@ -97,6 +97,28 @@ public class NotificationsController : ControllerBase return NoContent(); } + [HttpPatch("{id:guid}/unread")] + [HttpPatch("/notifications/{id:guid}/unread")] + public async Task MarkAsUnread(Guid id) + { + var notification = await _db.Notifications + .FirstOrDefaultAsync(n => n.Id == id); + + if (notification is null) + { + return NotFound(); + } + + if (notification.Lida) + { + notification.Lida = false; + notification.LidaEm = null; + await _db.SaveChangesAsync(); + } + + return NoContent(); + } + [HttpPatch("read-all")] [HttpPatch("/notifications/read-all")] public async Task MarkAllAsRead( @@ -114,6 +136,22 @@ public class NotificationsController : ControllerBase return NoContent(); } + [HttpPatch("unread-all")] + [HttpPatch("/notifications/unread-all")] + public async Task MarkAllAsUnread( + [FromQuery] string? filter, + [FromBody] NotificationSelectionRequest? request) + { + var query = ApplySelectionAndFilter(_db.Notifications, filter, request?.NotificationIds) + .Where(n => n.Lida); + + await query.ExecuteUpdateAsync(updates => updates + .SetProperty(n => n.Lida, false) + .SetProperty(n => n.LidaEm, (DateTime?)null)); + + return NoContent(); + } + [HttpGet("export")] [HttpGet("/notifications/export")] public async Task ExportNotifications([FromQuery] string? filter) diff --git a/Controllers/ParcelamentosController.cs b/Controllers/ParcelamentosController.cs index 65ac100..6d749f3 100644 --- a/Controllers/ParcelamentosController.cs +++ b/Controllers/ParcelamentosController.cs @@ -9,7 +9,7 @@ namespace line_gestao_api.Controllers; [ApiController] [Route("api/parcelamentos")] -[Authorize] +[Authorize(Roles = "admin")] public class ParcelamentosController : ControllerBase { private readonly AppDbContext _db;