Adds Name and LogoUrl for CreatedBy Content

This commit is contained in:
Jonathan Bourdon
2024-08-07 03:10:10 -04:00
parent 6d9201e8aa
commit f3b225d3a8
2 changed files with 33 additions and 3 deletions

View File

@@ -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<GetContentsByCreatorRequest, List<Content>>
: Endpoint<GetContentsByCreatorRequest, List<ContentModel>>
{
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);
}

View File

@@ -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);
}