diff --git a/src/Web/Features/Contents/Handlers/GetCreatorByAlias.cs b/src/Web/Features/Contents/Handlers/GetCreatorByAlias.cs index be4359a..cc3a677 100644 --- a/src/Web/Features/Contents/Handlers/GetCreatorByAlias.cs +++ b/src/Web/Features/Contents/Handlers/GetCreatorByAlias.cs @@ -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 + : Endpoint { 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); + } } } diff --git a/src/Web/Features/Contents/Handlers/Models/CreatorModel.cs b/src/Web/Features/Contents/Handlers/Models/CreatorModel.cs new file mode 100644 index 0000000..90492e5 --- /dev/null +++ b/src/Web/Features/Contents/Handlers/Models/CreatorModel.cs @@ -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; } +} diff --git a/src/Web/TestDataSeeder.cs b/src/Web/TestDataSeeder.cs index e32cc38..89b91dc 100644 --- a/src/Web/TestDataSeeder.cs +++ b/src/Web/TestDataSeeder.cs @@ -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 ]; }