From 7e9d373d68c39b5936624c974097e26dc1748dcc Mon Sep 17 00:00:00 2001 From: Eduardo Lopes <155753879+eduardolopesx03@users.noreply.github.com> Date: Thu, 22 Jan 2026 16:18:20 -0300 Subject: [PATCH] Return all notifications --- Controllers/NotificationsController.cs | 43 ++------------------------ 1 file changed, 2 insertions(+), 41 deletions(-) diff --git a/Controllers/NotificationsController.cs b/Controllers/NotificationsController.cs index bee46b7..d842ae2 100644 --- a/Controllers/NotificationsController.cs +++ b/Controllers/NotificationsController.cs @@ -1,5 +1,3 @@ -using System.IdentityModel.Tokens.Jwt; -using System.Security.Claims; using line_gestao_api.Data; using line_gestao_api.Dtos; using Microsoft.AspNetCore.Authorization; @@ -24,19 +22,7 @@ public class NotificationsController : ControllerBase [HttpGet("/notifications")] public async Task>> GetNotifications() { - var (userId, userName) = GetUserContext(); - if (userId is null && string.IsNullOrWhiteSpace(userName)) - { - return Unauthorized(); - } - - var userNameNormalized = userName?.Trim(); - - var query = _db.Notifications.AsNoTracking() - .Where(n => - (userId != null && n.UserId == userId) || - (userNameNormalized != null && n.Usuario != null && - EF.Functions.ILike(n.Usuario, userNameNormalized))); + var query = _db.Notifications.AsNoTracking(); var items = await query .OrderByDescending(n => n.Data) @@ -64,19 +50,8 @@ public class NotificationsController : ControllerBase [HttpPatch("/notifications/{id:guid}/read")] public async Task MarkAsRead(Guid id) { - var (userId, userName) = GetUserContext(); - if (userId is null && string.IsNullOrWhiteSpace(userName)) - { - return Unauthorized(); - } - - var userNameNormalized = userName?.Trim(); - var notification = await _db.Notifications - .FirstOrDefaultAsync(n => n.Id == id && - ((userId != null && n.UserId == userId) || - (userNameNormalized != null && n.Usuario != null && - EF.Functions.ILike(n.Usuario, userNameNormalized)))); + .FirstOrDefaultAsync(n => n.Id == id); if (notification is null) { @@ -93,18 +68,4 @@ public class NotificationsController : ControllerBase return NoContent(); } - private (Guid? UserId, string? UserName) GetUserContext() - { - var userIdRaw = User.FindFirstValue(JwtRegisteredClaimNames.Sub) - ?? User.FindFirstValue(ClaimTypes.NameIdentifier); - - Guid? userId = null; - if (Guid.TryParse(userIdRaw, out var parsed)) - { - userId = parsed; - } - - var userName = User.FindFirstValue("name"); - return (userId, userName); - } }