feat: pivot to social media workflow app
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 12:58:35 -04:00
parent 0f4acc1b6d
commit df3e602015
349 changed files with 18685 additions and 16010 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);
}
}