Adds subscriber count

This commit is contained in:
Jonathan Bourdon
2024-08-04 04:35:08 -04:00
parent 0cd913b274
commit 7ec668a822
3 changed files with 76 additions and 9 deletions

View File

@@ -1,6 +1,7 @@
using FastEndpoints; using FastEndpoints;
using FluentValidation; using FluentValidation;
using Hutopy.Web.Features.Contents.Data; using Hutopy.Web.Features.Contents.Data;
using Hutopy.Web.Features.Contents.Handlers.Models;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
namespace Hutopy.Web.Features.Contents.Handlers; namespace Hutopy.Web.Features.Contents.Handlers;
@@ -23,7 +24,7 @@ public sealed class GetCreatorByAliasRequestValidator
public class GetCreatorByAliasHandler( public class GetCreatorByAliasHandler(
ContentDbContext context) ContentDbContext context)
: Endpoint<GetCreatorByAliasRequest, Creator> : Endpoint<GetCreatorByAliasRequest, CreatorModel>
{ {
public override void Configure() public override void Configure()
{ {
@@ -40,13 +41,33 @@ public class GetCreatorByAliasHandler(
var creator = await context var creator = await context
.Creators .Creators
.SingleOrDefaultAsync( .Where(c => EF.Functions.Like(c.Name, creatorName))
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); cancellationToken: ct);
var creators = await context.Creators.ToListAsync(cancellationToken: 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,
};
if (creator is null) await SendNotFoundAsync(ct); await SendAsync(model, cancellation: ct);
else await SendAsync(creator, cancellation: ct); }
} }
} }

View 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; }
}

View File

@@ -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 = private readonly Creator[] _creators =
[ [
HutopyCreator, HutopyCreator,
ArpsCreator ArpsCreator,
ChloeCreator
]; ];
} }