Adds subscriber count
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using FastEndpoints;
|
||||
using FluentValidation;
|
||||
using Hutopy.Web.Features.Contents.Data;
|
||||
using Hutopy.Web.Features.Contents.Handlers.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Hutopy.Web.Features.Contents.Handlers;
|
||||
@@ -23,7 +24,7 @@ public sealed class GetCreatorByAliasRequestValidator
|
||||
|
||||
public class GetCreatorByAliasHandler(
|
||||
ContentDbContext context)
|
||||
: Endpoint<GetCreatorByAliasRequest, Creator>
|
||||
: Endpoint<GetCreatorByAliasRequest, CreatorModel>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
@@ -37,16 +38,36 @@ public class GetCreatorByAliasHandler(
|
||||
CancellationToken ct)
|
||||
{
|
||||
var creatorName = req.Name.ToLower();
|
||||
|
||||
|
||||
var creator = await context
|
||||
.Creators
|
||||
.SingleOrDefaultAsync(
|
||||
c => EF.Functions.Like(c.Name, creatorName),
|
||||
.Where(c => EF.Functions.Like(c.Name, creatorName))
|
||||
.FirstOrDefaultAsync(ct);
|
||||
|
||||
if (creator is null)
|
||||
{
|
||||
await SendNotFoundAsync(ct);
|
||||
}
|
||||
else
|
||||
{
|
||||
var subscriberCount = await context.Subscriptions.CountAsync(
|
||||
s => s.CreatorId == creator.Id,
|
||||
cancellationToken: ct);
|
||||
|
||||
var creators = await context.Creators.ToListAsync(cancellationToken: ct);
|
||||
|
||||
if (creator is null) await SendNotFoundAsync(ct);
|
||||
else await SendAsync(creator, cancellation: ct);
|
||||
var model = new CreatorModel
|
||||
{
|
||||
Id = creator.Id,
|
||||
CreatedBy = creator.CreatedBy,
|
||||
CreatedAt = creator.CreatedAt,
|
||||
Name = creator.Name,
|
||||
About = creator.About,
|
||||
SocialNetworks = creator.SocialNetworks,
|
||||
ProfileColors = creator.ProfileColors,
|
||||
StoredDataUrls = creator.StoredDataUrls,
|
||||
SubscriberCount = subscriberCount,
|
||||
};
|
||||
|
||||
await SendAsync(model, cancellation: ct);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
16
src/Web/Features/Contents/Handlers/Models/CreatorModel.cs
Normal file
16
src/Web/Features/Contents/Handlers/Models/CreatorModel.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using Hutopy.Web.Features.Contents.Data;
|
||||
|
||||
namespace Hutopy.Web.Features.Contents.Handlers.Models;
|
||||
|
||||
public class CreatorModel
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
public Guid CreatedBy { get; set; }
|
||||
public DateTimeOffset CreatedAt { get; set; }
|
||||
public string Name { get; set; }
|
||||
public About About { get; set; }
|
||||
public SocialNetworks SocialNetworks { get; set; }
|
||||
public ProfileColors ProfileColors { get; set; }
|
||||
public StoredDataUrls StoredDataUrls { get; set; }
|
||||
public int SubscriberCount { get; set; }
|
||||
}
|
||||
@@ -232,9 +232,39 @@ internal class TestDataSeeder(
|
||||
}
|
||||
};
|
||||
|
||||
private readonly static Creator ChloeCreator = new()
|
||||
{
|
||||
Name = "chloeprofile",
|
||||
About = new()
|
||||
{
|
||||
Title = "Page officielle",
|
||||
Description = "𝐿𝑎 𝑐𝑟𝑒́𝑎𝑡𝑖𝑣𝑖𝑡𝑒́ 𝑐’𝑒𝑠𝑡 𝑙’𝑖𝑛𝑡𝑒𝑙𝑙𝑖𝑔𝑒𝑛𝑐𝑒 𝑞𝑢𝑖 𝑠’𝑎𝑚𝑢𝑠𝑒!",
|
||||
},
|
||||
ProfileColors = new()
|
||||
{
|
||||
BannerTop = "#231F20",
|
||||
BannerBottom = "#272526",
|
||||
Accent = "#231F20",
|
||||
Menu = "#231F20",
|
||||
},
|
||||
SocialNetworks =
|
||||
new()
|
||||
{
|
||||
FacebookUrl = "https://www.facebook.com/chloegestionmedias",
|
||||
InstagramUrl = "https://www.instagram.com/chloe.photo_gms",
|
||||
|
||||
},
|
||||
StoredDataUrls = new()
|
||||
{
|
||||
BannerPictureUrl = "/images/usersmedia/chloebeaugrand/banners/bannerChloeBeaugrand01.png",
|
||||
ProfilePictureUrl = "/images/usersmedia/chloebeaugrand/profilepictures/profileChloeBeaugrand01.png"
|
||||
}
|
||||
};
|
||||
|
||||
private readonly Creator[] _creators =
|
||||
[
|
||||
HutopyCreator,
|
||||
ArpsCreator
|
||||
ArpsCreator,
|
||||
ChloeCreator
|
||||
];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user