72 lines
2.0 KiB
C#
72 lines
2.0 KiB
C#
using FastEndpoints;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Socialize.Api.Data;
|
|
using Socialize.Api.Infrastructure.Security;
|
|
using Socialize.Api.Modules.ContentItems.Data;
|
|
|
|
namespace Socialize.Api.Modules.ContentItems.Handlers;
|
|
|
|
public record ContentItemDetailDto(
|
|
Guid Id,
|
|
Guid WorkspaceId,
|
|
Guid ClientId,
|
|
Guid CampaignId,
|
|
string Title,
|
|
string PublicationMessage,
|
|
string PublicationTargets,
|
|
string? Hashtags,
|
|
string Status,
|
|
DateTimeOffset? DueDate,
|
|
string CurrentRevisionLabel,
|
|
int CurrentRevisionNumber,
|
|
DateTimeOffset CreatedAt);
|
|
|
|
public class GetContentItemHandler(
|
|
AppDbContext dbContext,
|
|
AccessScopeService accessScopeService)
|
|
: EndpointWithoutRequest<ContentItemDetailDto>
|
|
{
|
|
public override void Configure()
|
|
{
|
|
Get("/api/content-items/{id}");
|
|
Options(o => o.WithTags("Content Items"));
|
|
}
|
|
|
|
public override async Task HandleAsync(CancellationToken ct)
|
|
{
|
|
Guid id = Route<Guid>("id");
|
|
|
|
ContentItemDetailDto? item = await dbContext.ContentItems
|
|
.Where(candidate => candidate.Id == id)
|
|
.Select(candidate => new ContentItemDetailDto(
|
|
candidate.Id,
|
|
candidate.WorkspaceId,
|
|
candidate.ClientId,
|
|
candidate.CampaignId,
|
|
candidate.Title,
|
|
candidate.PublicationMessage,
|
|
candidate.PublicationTargets,
|
|
candidate.Hashtags,
|
|
candidate.Status,
|
|
candidate.DueDate,
|
|
candidate.CurrentRevisionLabel,
|
|
candidate.CurrentRevisionNumber,
|
|
candidate.CreatedAt))
|
|
.SingleOrDefaultAsync(ct);
|
|
|
|
if (item is null)
|
|
{
|
|
await SendNotFoundAsync(ct);
|
|
return;
|
|
}
|
|
|
|
if (!accessScopeService.CanReviewContent(User, item.WorkspaceId, item.ClientId, item.CampaignId))
|
|
{
|
|
await SendForbiddenAsync(ct);
|
|
return;
|
|
}
|
|
|
|
await SendOkAsync(item, ct);
|
|
}
|
|
}
|