Files
social-media/backend/Modules/Notifications/Handlers/MarkNotificationAsRead.cs
Jonathan Bourdon df3e602015
Some checks failed
Backend CI/CD / build_and_deploy (push) Has been cancelled
Frontend CI/CD / build_and_deploy (push) Has been cancelled
feat: pivot to social media workflow app
2026-04-24 12:58:35 -04:00

40 lines
1.1 KiB
C#

using Socialize.Infrastructure.Security;
using Socialize.Modules.Notifications.Data;
namespace Socialize.Modules.Notifications.Handlers;
public class MarkNotificationAsReadHandler(
AppDbContext dbContext,
AccessScopeService accessScopeService)
: EndpointWithoutRequest
{
public override void Configure()
{
Post("/api/notifications/{id}/read");
Options(o => o.WithTags("Notifications"));
}
public override async Task HandleAsync(CancellationToken ct)
{
Guid id = Route<Guid>("id");
NotificationEvent? notificationEvent = await dbContext.NotificationEvents.SingleOrDefaultAsync(candidate => candidate.Id == id, ct);
if (notificationEvent is null)
{
await SendNotFoundAsync(ct);
return;
}
if (!accessScopeService.CanAccessWorkspace(User, notificationEvent.WorkspaceId))
{
await SendForbiddenAsync(ct);
return;
}
notificationEvent.ReadAt = notificationEvent.ReadAt ?? DateTimeOffset.UtcNow;
await dbContext.SaveChangesAsync(ct);
await SendNoContentAsync(ct);
}
}