using Hutopy.Web.Common; using Hutopy.Web.Common.Security; using Hutopy.Web.Features.Contents.Data; namespace Hutopy.Web.Features.Contents.Handlers; [PublicAPI] public sealed class GetCreatorProfileResponse { public Guid Id { get; set; } public Guid CreatedBy { get; set; } public DateTimeOffset CreatedAt { get; set; } public string Title { get; set; } public string Name { get; set; } public bool Verified { get; set; } public bool AcceptDonation { get; set; } public Colors Colors { get; set; } public Images Images { get; set; } public PresentationInfos PresentationInfos { get; set; } public Socials Socials { get; set; } } [PublicAPI] public class GetCreatorProfileHandler( ContentDbContext context) : EndpointWithoutRequest { public override void Configure() { Get("/api/creators/profile"); Options((o => o.WithTags("Creators"))); AllowAnonymous(); } public override async Task HandleAsync( CancellationToken ct) { var creator = await context .Creators .Where(c => c.Id == HttpContext.User.GetUserId()) .AsNoTracking() .Select(c => new GetCreatorProfileResponse { Id = c.Id, CreatedBy = c.CreatedBy, CreatedAt = c.CreatedAt, Title = c.Title, Name = c.Slugs.NormalizedName, Verified = c.Verified, AcceptDonation = c.AcceptDonation, Colors = c.Colors, Images = c.Images, PresentationInfos = c.PresentationInfos, Socials = c.Socials, }) .SingleOrDefaultAsync(ct); if (creator is null) await SendNotFoundAsync(ct); else await SendAsync(creator, cancellation: ct); } }