39 lines
921 B
C#
39 lines
921 B
C#
using Hutopy.Web.Features.Contents.Data;
|
|
|
|
namespace Hutopy.Web.Features.Contents.Handlers;
|
|
|
|
[PublicAPI]
|
|
public sealed class GetContentRequest
|
|
{
|
|
public Guid ContentId { get; set; }
|
|
}
|
|
|
|
[PublicAPI]
|
|
public class GetContent(
|
|
ContentDbContext context)
|
|
: Endpoint<GetContentRequest, Content>
|
|
{
|
|
public override void Configure()
|
|
{
|
|
Get("/api/contents/{ContentId:guid}");
|
|
Options(o => o.WithTags("Contents"));
|
|
AllowAnonymous();
|
|
}
|
|
|
|
public override async Task HandleAsync(
|
|
GetContentRequest req,
|
|
CancellationToken ct)
|
|
{
|
|
var content = await context
|
|
.Contents
|
|
.SingleOrDefaultAsync(
|
|
c => c.Id == req.ContentId,
|
|
cancellationToken: ct);
|
|
|
|
if (content is null)
|
|
await SendNotFoundAsync(cancellation: ct);
|
|
else
|
|
await SendAsync(content, cancellation: ct);
|
|
}
|
|
}
|