Adds Creator's Color to each Content response
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
using Hutopy.Web.Features.Contents.Data;
|
using Hutopy.Web.Features.Contents.Data;
|
||||||
|
using Hutopy.Web.Features.Contents.Handlers.Models;
|
||||||
|
|
||||||
namespace Hutopy.Web.Features.Contents.Handlers;
|
namespace Hutopy.Web.Features.Contents.Handlers;
|
||||||
|
|
||||||
@@ -11,7 +12,7 @@ public sealed class GetContentRequest
|
|||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
public class GetContent(
|
public class GetContent(
|
||||||
ContentDbContext context)
|
ContentDbContext context)
|
||||||
: Endpoint<GetContentRequest, Content>
|
: Endpoint<GetContentRequest, ContentModel>
|
||||||
{
|
{
|
||||||
public override void Configure()
|
public override void Configure()
|
||||||
{
|
{
|
||||||
@@ -26,6 +27,19 @@ public class GetContent(
|
|||||||
{
|
{
|
||||||
var content = await context
|
var content = await context
|
||||||
.Contents
|
.Contents
|
||||||
|
.Select(c => new ContentModel
|
||||||
|
{
|
||||||
|
Id = c.Id,
|
||||||
|
CreatedBy = c.CreatedBy,
|
||||||
|
CreatedByName = c.Creator!.Name,
|
||||||
|
CreatedByPortraitUrl = c.Creator.Images.Logo,
|
||||||
|
CreatedAt = c.CreatedAt,
|
||||||
|
ColorMenu = c.Creator.Colors.Menu,
|
||||||
|
ColorAccent = c.Creator.Colors.Accent,
|
||||||
|
Title = c.Title,
|
||||||
|
Description = c.Description,
|
||||||
|
Urls = c.Urls,
|
||||||
|
})
|
||||||
.SingleOrDefaultAsync(
|
.SingleOrDefaultAsync(
|
||||||
c => c.Id == req.ContentId,
|
c => c.Id == req.ContentId,
|
||||||
cancellationToken: ct);
|
cancellationToken: ct);
|
||||||
|
|||||||
@@ -30,10 +30,20 @@ public class GetContentsByCreatorHandler(
|
|||||||
{
|
{
|
||||||
var queryBuilder = new StringBuilder();
|
var queryBuilder = new StringBuilder();
|
||||||
queryBuilder.AppendLine($"""
|
queryBuilder.AppendLine($"""
|
||||||
SELECT content."Id", content."CreatedBy", creator."Name" as CreatedByName, i."Logo" as CreatedByPortraitUrl, content."CreatedAt", content."Title", content."Description", content."Urls"
|
SELECT content."Id",
|
||||||
|
content."CreatedBy",
|
||||||
|
creator."Name" as CreatedByName,
|
||||||
|
i."Logo" as CreatedByPortraitUrl,
|
||||||
|
c."Menu" as ColorMenu,
|
||||||
|
c."Accent" as ColorAccent,
|
||||||
|
content."CreatedAt",
|
||||||
|
content."Title",
|
||||||
|
content."Description",
|
||||||
|
content."Urls"
|
||||||
FROM "Content"."Contents" AS content
|
FROM "Content"."Contents" AS content
|
||||||
INNER JOIN "Content"."Creators" AS creator ON content."CreatedBy" = creator."Id"
|
INNER JOIN "Content"."Creators" AS creator ON content."CreatedBy" = creator."Id"
|
||||||
LEFT JOIN "Content"."Images" AS i ON creator."Id" = i."CreatorId"
|
LEFT JOIN "Content"."Images" AS i ON creator."Id" = i."CreatorId"
|
||||||
|
LEFT JOIN "Content"."Colors" AS c ON creator."Id" = c."CreatorId"
|
||||||
WHERE content."CreatedBy" = '{req.CreatorId}'
|
WHERE content."CreatedBy" = '{req.CreatorId}'
|
||||||
""");
|
""");
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ public class ContentModel
|
|||||||
public required Guid CreatedBy { get; init; }
|
public required Guid CreatedBy { get; init; }
|
||||||
public required string CreatedByName { get; init; }
|
public required string CreatedByName { get; init; }
|
||||||
public required string? CreatedByPortraitUrl { get; init; }
|
public required string? CreatedByPortraitUrl { get; init; }
|
||||||
|
public required string? ColorMenu { get; init; }
|
||||||
|
public required string? ColorAccent { get; init; }
|
||||||
public required DateTimeOffset CreatedAt { get; init; }
|
public required DateTimeOffset CreatedAt { get; init; }
|
||||||
public required string Title { get; init; }
|
public required string Title { get; init; }
|
||||||
public required string Description { get; init; }
|
public required string Description { get; init; }
|
||||||
|
|||||||
Reference in New Issue
Block a user