feat: add release communications
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Socialize.Api.Data;
|
||||
using Socialize.Api.Infrastructure.Security;
|
||||
using Socialize.Api.Modules.ReleaseCommunications.Contracts;
|
||||
using Socialize.Api.Modules.ReleaseCommunications.Data;
|
||||
using Socialize.Api.Modules.ReleaseCommunications.Services;
|
||||
|
||||
namespace Socialize.Api.Modules.ReleaseCommunications.Handlers;
|
||||
|
||||
internal class GetUnreadReleaseUpdatesHandler(AppDbContext dbContext)
|
||||
: EndpointWithoutRequest<ReleaseUpdateUnreadSummaryDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Get("/api/release-updates/unread");
|
||||
Options(o => o.WithTags("Release Communications"));
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(CancellationToken ct)
|
||||
{
|
||||
Guid userId = User.GetUserId();
|
||||
ReleaseUpdateAudienceContext audienceContext =
|
||||
await ReleaseUpdateVisibility.GetAudienceContextAsync(dbContext, User, userId, ct);
|
||||
|
||||
List<ReleaseUpdate> unreadUpdates = await dbContext.ReleaseUpdates
|
||||
.VisibleTo(audienceContext)
|
||||
.Where(update => !dbContext.ReleaseUpdateReadReceipts.Any(receipt =>
|
||||
receipt.ReleaseUpdateId == update.Id &&
|
||||
receipt.UserId == userId))
|
||||
.OrderByDescending(update => update.PublishedAt)
|
||||
.ThenByDescending(update => update.CreatedAt)
|
||||
.ToListAsync(ct);
|
||||
|
||||
await SendOkAsync(
|
||||
new ReleaseUpdateUnreadSummaryDto(
|
||||
unreadUpdates.Count,
|
||||
unreadUpdates.Count(update => update.Importance == ReleaseUpdateImportance.Important),
|
||||
unreadUpdates.Select(update => update.ToDto(false)).ToArray()),
|
||||
ct);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user