feat: pivot to social media workflow app
This commit is contained in:
68
backend/Modules/ContentItems/Handlers/GetContentItem.cs
Normal file
68
backend/Modules/ContentItems/Handlers/GetContentItem.cs
Normal file
@@ -0,0 +1,68 @@
|
||||
using Socialize.Infrastructure.Security;
|
||||
using Socialize.Modules.ContentItems.Data;
|
||||
|
||||
namespace Socialize.Modules.ContentItems.Handlers;
|
||||
|
||||
public record ContentItemDetailDto(
|
||||
Guid Id,
|
||||
Guid WorkspaceId,
|
||||
Guid ClientId,
|
||||
Guid ProjectId,
|
||||
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.ProjectId,
|
||||
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.ProjectId))
|
||||
{
|
||||
await SendForbiddenAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
await SendOkAsync(item, ct);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user