chore: moving towards agentic development
Some checks failed
Backend CI/CD / build_and_deploy (push) Has been cancelled
Frontend CI/CD / build_and_deploy (push) Has been cancelled

This commit is contained in:
2026-04-24 21:12:26 -04:00
parent df3e602015
commit b6eb692c27
179 changed files with 2880 additions and 866 deletions

View File

@@ -0,0 +1,88 @@
using Socialize.Infrastructure.Security;
namespace Socialize.Modules.Notifications.Handlers;
public record GetNotificationsRequest(Guid? WorkspaceId, Guid? ContentItemId);
public record NotificationEventDto(
Guid Id,
Guid WorkspaceId,
Guid? ContentItemId,
string EventType,
string EntityType,
Guid EntityId,
string Message,
Guid? RecipientUserId,
string? RecipientEmail,
string? MetadataJson,
DateTimeOffset CreatedAt,
DateTimeOffset? ReadAt);
public class GetNotificationsHandler(
AppDbContext dbContext,
AccessScopeService accessScopeService)
: Endpoint<GetNotificationsRequest, IReadOnlyCollection<NotificationEventDto>>
{
public override void Configure()
{
Get("/api/notifications");
Options(o => o.WithTags("Notifications"));
}
public override async Task HandleAsync(GetNotificationsRequest request, CancellationToken ct)
{
if (request.ContentItemId.HasValue)
{
ContentItem? item = await dbContext.ContentItems
.SingleOrDefaultAsync(candidate => candidate.Id == request.ContentItemId.Value, ct);
if (item is null)
{
await SendNotFoundAsync(ct);
return;
}
if (!accessScopeService.CanReviewContent(User, item.WorkspaceId, item.ClientId, item.ProjectId))
{
await SendForbiddenAsync(ct);
return;
}
}
IQueryable<NotificationEvent> query = dbContext.NotificationEvents.AsQueryable();
if (!accessScopeService.IsManager(User))
{
IReadOnlyCollection<Guid> workspaceScopeIds = User.GetWorkspaceScopeIds();
query = query.Where(notificationEvent => workspaceScopeIds.Contains(notificationEvent.WorkspaceId));
}
if (request.WorkspaceId.HasValue)
{
query = query.Where(notificationEvent => notificationEvent.WorkspaceId == request.WorkspaceId.Value);
}
if (request.ContentItemId.HasValue)
{
query = query.Where(notificationEvent => notificationEvent.ContentItemId == request.ContentItemId.Value);
}
List<NotificationEventDto> notifications = await query
.OrderByDescending(notificationEvent => notificationEvent.CreatedAt)
.Take(100)
.Select(notificationEvent => new NotificationEventDto(
notificationEvent.Id,
notificationEvent.WorkspaceId,
notificationEvent.ContentItemId,
notificationEvent.EventType,
notificationEvent.EntityType,
notificationEvent.EntityId,
notificationEvent.Message,
notificationEvent.RecipientUserId,
notificationEvent.RecipientEmail,
notificationEvent.MetadataJson,
notificationEvent.CreatedAt,
notificationEvent.ReadAt))
.ToListAsync(ct);
await SendOkAsync(notifications, ct);
}
}

View File

@@ -0,0 +1,39 @@
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);
}
}