Adds messages api

This commit is contained in:
Jonathan Bourdon
2024-06-27 12:37:59 -04:00
parent 891597fb08
commit 72e243cf84
21 changed files with 485 additions and 61 deletions

View File

@@ -0,0 +1,30 @@
using FastEndpoints;
using Hutopy.Web.Messages.Data;
using Microsoft.EntityFrameworkCore;
namespace Hutopy.Web.Messages.Handlers;
public class GetMessages(
MessagingDbContext context)
: EndpointWithoutRequest<List<Message>>
{
public override void Configure()
{
Tags("Messages");
Get("/api/messages/{ContentId:guid}");
AllowAnonymous();
}
public override async Task HandleAsync(
CancellationToken ct)
{
var contentId = Route<Guid>("ContentId");
var comments = await context
.Messages
.Where(c => c.ContentId == contentId)
.ToListAsync(cancellationToken: ct);
await SendAsync(comments, cancellation: ct);
}
}