65 lines
2.0 KiB
C#
65 lines
2.0 KiB
C#
using Socialize.Infrastructure.Security;
|
|
namespace Socialize.Modules.ContentItems.Handlers;
|
|
|
|
public record ContentItemRevisionDto(
|
|
Guid Id,
|
|
Guid ContentItemId,
|
|
int RevisionNumber,
|
|
string RevisionLabel,
|
|
string Title,
|
|
string PublicationMessage,
|
|
string PublicationTargets,
|
|
string? Hashtags,
|
|
string? ChangeSummary,
|
|
Guid? CreatedByUserId,
|
|
DateTimeOffset CreatedAt);
|
|
|
|
public class GetContentItemRevisionsHandler(
|
|
AppDbContext dbContext,
|
|
AccessScopeService accessScopeService)
|
|
: EndpointWithoutRequest<IReadOnlyCollection<ContentItemRevisionDto>>
|
|
{
|
|
public override void Configure()
|
|
{
|
|
Get("/api/content-items/{id}/revisions");
|
|
Options(o => o.WithTags("Content Items"));
|
|
}
|
|
|
|
public override async Task HandleAsync(CancellationToken ct)
|
|
{
|
|
Guid id = Route<Guid>("id");
|
|
|
|
ContentItem? item = await dbContext.ContentItems.SingleOrDefaultAsync(candidate => candidate.Id == id, ct);
|
|
if (item is null)
|
|
{
|
|
await SendNotFoundAsync(ct);
|
|
return;
|
|
}
|
|
|
|
if (!accessScopeService.CanReviewContent(User, item.WorkspaceId, item.ClientId, item.ProjectId))
|
|
{
|
|
await SendForbiddenAsync(ct);
|
|
return;
|
|
}
|
|
|
|
List<ContentItemRevisionDto> revisions = await dbContext.ContentItemRevisions
|
|
.Where(revision => revision.ContentItemId == id)
|
|
.OrderByDescending(revision => revision.RevisionNumber)
|
|
.Select(revision => new ContentItemRevisionDto(
|
|
revision.Id,
|
|
revision.ContentItemId,
|
|
revision.RevisionNumber,
|
|
revision.RevisionLabel,
|
|
revision.Title,
|
|
revision.PublicationMessage,
|
|
revision.PublicationTargets,
|
|
revision.Hashtags,
|
|
revision.ChangeSummary,
|
|
revision.CreatedByUserId,
|
|
revision.CreatedAt))
|
|
.ToListAsync(ct);
|
|
|
|
await SendOkAsync(revisions, ct);
|
|
}
|
|
}
|