Adds Messaging streaming

This commit is contained in:
Jonathan Bourdon
2024-07-19 00:44:03 -04:00
parent 8b5ab2d769
commit d268625f19
9 changed files with 80 additions and 58 deletions

View File

@@ -4,7 +4,7 @@ public class Content
{
public Guid Id { get; init; }
public Guid CreatedBy { get; init; }
public DateTimeOffset CreatedAt { get; }
public DateTimeOffset CreatedAt { get; init; }
public string? Title { get; init; }
public string? Description { get; init; }

View File

@@ -4,14 +4,14 @@ using Microsoft.EntityFrameworkCore;
namespace Hutopy.Web.Features.Contents.Handlers;
public sealed class GetContentsRequest
public sealed class GetContentRequest
{
public Guid ContentId { get; set; }
}
public class GetContents(
public class GetContent(
ContentDbContext context)
: Endpoint<GetContentsRequest, Content>
: Endpoint<GetContentRequest, Content>
{
public override void Configure()
{
@@ -21,7 +21,7 @@ public class GetContents(
}
public override async Task HandleAsync(
GetContentsRequest req,
GetContentRequest req,
CancellationToken ct)
{
var content = await context

View File

@@ -7,7 +7,7 @@ namespace Hutopy.Web.Features.Contents.Handlers;
public sealed class GetContentsByUserRequest
{
public Guid UserId { get; set; }
[BindFrom("max_items")] public int MaxItems { get; set; } = 10;
[BindFrom("page_size")] public int PageSize { get; set; } = 10;
[BindFrom("last_id")] public Guid? LastId { get; set; }
}
@@ -30,12 +30,12 @@ public class GetContentsByUser(
.Contents
.Where(c => c.CreatedBy == req.UserId);
if (req.LastId is not null)
query = query.OrderByDescending(c => c.Id).Where(c => c.Id < req.LastId.Value);
else
query = query.OrderByDescending(c => c.Id);
query = query.OrderByDescending(c => c.CreatedAt);
query = query.Take(req.MaxItems);
if (req.LastId is not null)
query = query.Where(c => c.Id < req.LastId.Value);
query = query.Take(req.PageSize);
var posts = await query.ToListAsync(cancellationToken: ct);