diff --git a/src/Web/Features/Contents/Handlers/GetContentsByCreator.cs b/src/Web/Features/Contents/Handlers/GetContentsByCreator.cs index 3ec2e83..8e2f5fd 100644 --- a/src/Web/Features/Contents/Handlers/GetContentsByCreator.cs +++ b/src/Web/Features/Contents/Handlers/GetContentsByCreator.cs @@ -1,5 +1,7 @@ -using FastEndpoints; +using System.Linq.Expressions; +using FastEndpoints; using Hutopy.Web.Features.Contents.Data; +using Hutopy.Web.Features.Contents.Handlers.Models; using Microsoft.EntityFrameworkCore; namespace Hutopy.Web.Features.Contents.Handlers; @@ -13,7 +15,7 @@ public sealed class GetContentsByCreatorRequest public class GetContentsByCreatorHandler( ContentDbContext context) - : Endpoint> + : Endpoint> { public override void Configure() { @@ -37,7 +39,9 @@ public class GetContentsByCreatorHandler( query = query.Take(req.PageSize); - var posts = await query.ToListAsync(cancellationToken: ct); + var posts = await query + .Select(x => x.ToResponse()) + .ToListAsync(cancellationToken: ct); await SendAsync(posts, cancellation: ct); } diff --git a/src/Web/Features/Contents/Handlers/Models/ContentModel.cs b/src/Web/Features/Contents/Handlers/Models/ContentModel.cs new file mode 100644 index 0000000..0d1439e --- /dev/null +++ b/src/Web/Features/Contents/Handlers/Models/ContentModel.cs @@ -0,0 +1,26 @@ +using Hutopy.Web.Features.Contents.Data; + +namespace Hutopy.Web.Features.Contents.Handlers.Models; + +public record struct ContentModel( + Guid Id, + Guid CreatedBy, + string CreatedByName, + string? CreatedByPortraitUrl, + DateTimeOffset CreatedAt, + string Title, + string Description, + string[]? Urls); + +public static class ContentExtensions +{ + public static ContentModel ToResponse(this Content c) => new( + c.Id, + c.CreatedBy, + c.Creator!.Name, + c.Creator.Images.Logo, + c.CreatedAt, + c.Title, + c.Description, + c.Urls); +}