Adds Name and LogoUrl for CreatedBy Content
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
26
src/Web/Features/Contents/Handlers/Models/ContentModel.cs
Normal file
26
src/Web/Features/Contents/Handlers/Models/ContentModel.cs
Normal 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);
|
||||
}
|
||||
Reference in New Issue
Block a user