34 lines
820 B
C#
34 lines
820 B
C#
using FastEndpoints;
|
|
using Hutopy.Web.Messages.Data;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace Hutopy.Web.Messages.Handlers;
|
|
|
|
public record GetMessagesByUserRequest(
|
|
[FromRoute] Guid UserId);
|
|
|
|
public class GetMessagesByUser(
|
|
MessagingDbContext context)
|
|
: EndpointWithoutRequest<List<Message>>
|
|
{
|
|
public override void Configure()
|
|
{
|
|
Tags("Messages");
|
|
Get("/api/messages/by-user/{UserId:guid}");
|
|
}
|
|
|
|
public override async Task HandleAsync(
|
|
CancellationToken ct)
|
|
{
|
|
var userId = Route<Guid>("UserId");
|
|
|
|
var posts = await context
|
|
.Messages
|
|
.Where(c => c.CreatedBy == userId)
|
|
.ToListAsync(cancellationToken: ct);
|
|
|
|
await SendAsync(posts, cancellation: ct);
|
|
}
|
|
}
|