Adds AcceptDonation to Creator. Sync Content's Creator to Membership's Creator

This commit is contained in:
2025-01-08 21:22:00 -05:00
parent 44d202b906
commit ede5483bbf
10 changed files with 501 additions and 59 deletions

View File

@@ -7,6 +7,7 @@ public class Creator
public Guid Id { get; set; }
public Guid CreatedBy { get; set; }
public DateTimeOffset CreatedAt { get; init; }
public bool AcceptDonation { get; set; }
public bool Verified { get; set; }
[MaxLength(255)] public string Name { get; set; } = null!;
[MaxLength(255)] public string NormalizedName { get; set; } = null!;

View File

@@ -0,0 +1,406 @@
// <auto-generated />
using System;
using Hutopy.Web.Features.Contents.Data;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace Hutopy.Web.Features.Contents.Data.Migrations
{
[DbContext(typeof(ContentDbContext))]
[Migration("20250109015556_Adds_AcceptDonation_Creator")]
partial class Adds_AcceptDonation_Creator
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasDefaultSchema("Content")
.HasAnnotation("ProductVersion", "8.0.10")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("Hutopy.Web.Features.Contents.Data.Content", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<DateTimeOffset>("CreatedAt")
.ValueGeneratedOnAdd()
.HasColumnType("timestamp with time zone")
.HasDefaultValueSql("CURRENT_TIMESTAMP");
b.Property<Guid>("CreatedBy")
.HasColumnType("uuid");
b.Property<DateTimeOffset?>("DeletedAt")
.HasColumnType("timestamp with time zone");
b.Property<Guid?>("DeletedBy")
.HasColumnType("uuid");
b.Property<string>("Description")
.IsRequired()
.HasMaxLength(2048)
.HasColumnType("character varying(2048)");
b.Property<string>("HtmlFileUrl")
.HasMaxLength(2048)
.HasColumnType("character varying(2048)");
b.Property<string>("ThumbnailUrl")
.HasMaxLength(512)
.HasColumnType("character varying(512)");
b.Property<string>("Title")
.IsRequired()
.HasMaxLength(128)
.HasColumnType("character varying(128)");
b.Property<string[]>("Urls")
.HasColumnType("text[]");
b.HasKey("Id");
b.HasIndex("CreatedBy");
b.ToTable("Contents", "Content");
});
modelBuilder.Entity("Hutopy.Web.Features.Contents.Data.Creator", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<bool>("AcceptDonation")
.HasColumnType("boolean");
b.Property<DateTimeOffset>("CreatedAt")
.HasColumnType("timestamp with time zone");
b.Property<Guid>("CreatedBy")
.HasColumnType("uuid");
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(255)
.HasColumnType("character varying(255)");
b.Property<string>("NormalizedName")
.IsRequired()
.ValueGeneratedOnAddOrUpdate()
.HasMaxLength(255)
.HasColumnType("character varying(255)")
.HasComputedColumnSql("LOWER( \"Content\".\"Creators\".\"Name\")", true);
b.Property<string>("Title")
.HasMaxLength(255)
.HasColumnType("character varying(255)");
b.Property<bool>("Verified")
.HasColumnType("boolean");
b.HasKey("Id");
b.HasIndex("NormalizedName")
.IsUnique();
b.ToTable("Creators", "Content");
});
modelBuilder.Entity("Hutopy.Web.Features.Contents.Data.Content", b =>
{
b.HasOne("Hutopy.Web.Features.Contents.Data.Creator", "Creator")
.WithMany()
.HasForeignKey("CreatedBy")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.OwnsMany("Hutopy.Web.Features.Contents.Data.ContentReaction", "Reactions", b1 =>
{
b1.Property<Guid>("ContentId")
.HasColumnType("uuid");
b1.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b1.Property<int>("Id"));
b1.Property<int>("Reaction")
.HasColumnType("integer");
b1.Property<Guid>("UserId")
.HasColumnType("uuid");
b1.Property<string>("UserName")
.IsRequired()
.HasMaxLength(128)
.HasColumnType("character varying(128)");
b1.HasKey("ContentId", "Id");
b1.ToTable("Reactions", "Content");
b1.WithOwner()
.HasForeignKey("ContentId");
});
b.Navigation("Creator");
b.Navigation("Reactions");
});
modelBuilder.Entity("Hutopy.Web.Features.Contents.Data.Creator", b =>
{
b.OwnsOne("Hutopy.Web.Features.Contents.Data.Colors", "Colors", b1 =>
{
b1.Property<Guid>("CreatorId")
.HasColumnType("uuid");
b1.Property<string>("Background")
.IsRequired()
.HasMaxLength(9)
.HasColumnType("character varying(9)");
b1.Property<string>("Error")
.IsRequired()
.HasMaxLength(9)
.HasColumnType("character varying(9)");
b1.Property<string>("OnBackground")
.IsRequired()
.HasMaxLength(9)
.HasColumnType("character varying(9)");
b1.Property<string>("OnError")
.IsRequired()
.HasMaxLength(9)
.HasColumnType("character varying(9)");
b1.Property<string>("OnPrimary")
.IsRequired()
.HasMaxLength(9)
.HasColumnType("character varying(9)");
b1.Property<string>("OnSecondary")
.IsRequired()
.HasMaxLength(9)
.HasColumnType("character varying(9)");
b1.Property<string>("OnSurface")
.IsRequired()
.HasMaxLength(9)
.HasColumnType("character varying(9)");
b1.Property<string>("Primary")
.IsRequired()
.HasMaxLength(9)
.HasColumnType("character varying(9)");
b1.Property<string>("Secondary")
.IsRequired()
.HasMaxLength(9)
.HasColumnType("character varying(9)");
b1.Property<string>("Surface")
.IsRequired()
.HasMaxLength(9)
.HasColumnType("character varying(9)");
b1.HasKey("CreatorId");
b1.ToTable("Colors", "Content");
b1.WithOwner()
.HasForeignKey("CreatorId");
});
b.OwnsOne("Hutopy.Web.Features.Contents.Data.Images", "Images", b1 =>
{
b1.Property<Guid>("CreatorId")
.HasColumnType("uuid");
b1.Property<string>("Banner")
.HasMaxLength(255)
.HasColumnType("character varying(255)");
b1.Property<string>("Logo")
.HasMaxLength(255)
.HasColumnType("character varying(255)");
b1.HasKey("CreatorId");
b1.ToTable("Images", "Content");
b1.WithOwner()
.HasForeignKey("CreatorId");
});
b.OwnsOne("Hutopy.Web.Features.Contents.Data.PresentationInfos", "PresentationInfos", b1 =>
{
b1.Property<Guid>("CreatorId")
.HasColumnType("uuid");
b1.Property<string>("Email")
.IsRequired()
.HasMaxLength(255)
.HasColumnType("character varying(255)");
b1.Property<string>("Image1Url")
.IsRequired()
.HasMaxLength(2000)
.HasColumnType("character varying(2000)");
b1.Property<string>("Image2Url")
.IsRequired()
.HasMaxLength(2000)
.HasColumnType("character varying(2000)");
b1.Property<string>("Image3Url")
.IsRequired()
.HasMaxLength(2000)
.HasColumnType("character varying(2000)");
b1.Property<string>("Image4Url")
.IsRequired()
.HasMaxLength(2000)
.HasColumnType("character varying(2000)");
b1.Property<string>("ImagesSubtitle")
.IsRequired()
.HasMaxLength(2000)
.HasColumnType("character varying(2000)");
b1.Property<string>("ImagesText")
.IsRequired()
.HasMaxLength(10000)
.HasColumnType("character varying(10000)");
b1.Property<string>("MainImageText")
.IsRequired()
.HasMaxLength(10000)
.HasColumnType("character varying(10000)");
b1.Property<string>("MainImageUrl")
.IsRequired()
.HasMaxLength(2000)
.HasColumnType("character varying(2000)");
b1.Property<string>("MainVideoText")
.IsRequired()
.HasMaxLength(10000)
.HasColumnType("character varying(10000)");
b1.Property<string>("PhoneNumber")
.IsRequired()
.HasMaxLength(255)
.HasColumnType("character varying(255)");
b1.Property<string>("Title")
.IsRequired()
.HasMaxLength(2000)
.HasColumnType("character varying(2000)");
b1.Property<string>("VideoSubtitle")
.IsRequired()
.HasMaxLength(2000)
.HasColumnType("character varying(2000)");
b1.Property<string>("VideoSubtitleMain")
.IsRequired()
.HasMaxLength(2000)
.HasColumnType("character varying(2000)");
b1.Property<string>("VideoText")
.IsRequired()
.HasMaxLength(10000)
.HasColumnType("character varying(10000)");
b1.Property<string>("VideoUrl")
.IsRequired()
.HasMaxLength(2000)
.HasColumnType("character varying(2000)");
b1.Property<string>("VideoUrlMain")
.IsRequired()
.HasMaxLength(2000)
.HasColumnType("character varying(2000)");
b1.HasKey("CreatorId");
b1.ToTable("PresentationInfos", "Content");
b1.WithOwner()
.HasForeignKey("CreatorId");
});
b.OwnsOne("Hutopy.Web.Features.Contents.Data.Socials", "Socials", b1 =>
{
b1.Property<Guid>("CreatorId")
.HasColumnType("uuid");
b1.Property<string>("FacebookUrl")
.HasMaxLength(255)
.HasColumnType("character varying(255)");
b1.Property<string>("InstagramUrl")
.HasMaxLength(255)
.HasColumnType("character varying(255)");
b1.Property<string>("LinkedInUrl")
.HasMaxLength(255)
.HasColumnType("character varying(255)");
b1.Property<string>("RedditUrl")
.HasMaxLength(255)
.HasColumnType("character varying(255)");
b1.Property<string>("TikTokUrl")
.HasMaxLength(255)
.HasColumnType("character varying(255)");
b1.Property<string>("WebsiteUrl")
.HasMaxLength(255)
.HasColumnType("character varying(255)");
b1.Property<string>("XUrl")
.HasMaxLength(255)
.HasColumnType("character varying(255)");
b1.Property<string>("YoutubeUrl")
.HasMaxLength(255)
.HasColumnType("character varying(255)");
b1.HasKey("CreatorId");
b1.ToTable("Socials", "Content");
b1.WithOwner()
.HasForeignKey("CreatorId");
});
b.Navigation("Colors")
.IsRequired();
b.Navigation("Images")
.IsRequired();
b.Navigation("PresentationInfos")
.IsRequired();
b.Navigation("Socials")
.IsRequired();
});
#pragma warning restore 612, 618
}
}
}

View File

@@ -0,0 +1,31 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Hutopy.Web.Features.Contents.Data.Migrations
{
/// <inheritdoc />
public partial class Adds_AcceptDonation_Creator : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<bool>(
name: "AcceptDonation",
schema: "Content",
table: "Creators",
type: "boolean",
nullable: false,
defaultValue: false);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "AcceptDonation",
schema: "Content",
table: "Creators");
}
}
}

View File

@@ -77,6 +77,9 @@ namespace Hutopy.Web.Features.Contents.Data.Migrations
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<bool>("AcceptDonation")
.HasColumnType("boolean");
b.Property<DateTimeOffset>("CreatedAt")
.HasColumnType("timestamp with time zone");

View File

@@ -0,0 +1,43 @@
using Hutopy.Web.Features.Contents.Data;
using Hutopy.Web.Features.Memberships.Events;
namespace Hutopy.Web.Features.Contents.EventHandlers;
[UsedImplicitly]
public class StripeAccountConfiguredHandler(
ILogger<StripeAccountConfiguredHandler> logger,
IServiceScopeFactory scopeFactory)
: IEventHandler<StripeAccountConfigured>
{
public async Task HandleAsync(
StripeAccountConfigured eventModel,
CancellationToken ct)
{
using var scope = scopeFactory.CreateScope();
await using var dbContext = scope.ServiceProvider.GetRequiredService<ContentDbContext>();
var creator = await dbContext.FindAsync<Creator>(
[eventModel.CreatorId],
cancellationToken: ct);
if (creator is null)
{
logger.LogError(
"Creator with id {CreatorId} was not found.",
eventModel.CreatorId);
return;
}
creator.AcceptDonation = true;
var rows = await dbContext.SaveChangesAsync(ct);
if (rows is 0 or > 1)
{
logger.LogError(
"An error occured while updating Creator with id {CreatorId}: rows:{Rows}",
eventModel.CreatorId,
rows);
}
}
}

View File

@@ -15,6 +15,7 @@ public record struct GetCreatorByAliasResponse(
Guid CreatedBy,
DateTimeOffset CreatedAt,
bool Verified,
bool AcceptDonation,
string Name,
string? Title,
Socials Socials,
@@ -68,6 +69,7 @@ public class GetCreatorByAliasHandler(
creator.CreatedBy,
creator.CreatedAt,
creator.Verified,
creator.AcceptDonation,
creator.Name,
creator.Title,
creator.Socials,

View File

@@ -4,6 +4,6 @@ public class Creator
{
public Guid Id { get; set; }
public string Name { get; set; }
public string StripeAccountId { get; set; }
public string? StripeAccountId { get; set; }
public string PortraitUrl { get; set; }
}

View File

@@ -0,0 +1,5 @@
namespace Hutopy.Web.Features.Memberships.Events;
public record StripeAccountConfigured(
Guid CreatorId,
string StripeAccountId);

View File

@@ -1,6 +1,6 @@
using Hutopy.Web.Common.Security;
using Hutopy.Web.Features.Memberships.Data;
using Hutopy.Web.Features.Memberships.Infrastructure;
using Hutopy.Web.Features.Memberships.Events;
namespace Hutopy.Web.Features.Memberships.Handlers;
@@ -9,13 +9,12 @@ public record struct ChangeStripeIdRequest(
string StripeAccountId);
public class ChangeStripeIdHandler(
MembershipDbContext dbContext,
StripeService stripeService)
MembershipDbContext dbContext)
: Endpoint<ChangeStripeIdRequest>
{
public override void Configure()
{
Post("/api/creators/stripe-account");
Post("/api/membership/stripe-account");
Options(o => o.WithTags("Memberships"));
}
@@ -36,17 +35,21 @@ public class ChangeStripeIdHandler(
creator = new Creator
{
Id = creatorId,
Name = HttpContext.User.GetAlias() ?? creatorId.ToString()
Name = HttpContext.User.GetAlias() ?? creatorId.ToString(),
PortraitUrl = HttpContext.User.GetPortraitUrl() ?? string.Empty
};
await dbContext.AddAsync(creator, ct);
}
creator.StripeAccountId = req.StripeAccountId;
creator.PortraitUrl = HttpContext.User.GetPortraitUrl();
await dbContext.SaveChangesAsync(ct);
await PublishAsync(
new StripeAccountConfigured(creator.Id, creator.StripeAccountId),
cancellation: ct);
await SendOkAsync(creator.Id, ct);
}
}

View File

@@ -1,52 +0,0 @@
using Hutopy.Web.Common.Security;
using Hutopy.Web.Features.Memberships.Data;
using Hutopy.Web.Features.Memberships.Infrastructure;
namespace Hutopy.Web.Features.Memberships.Handlers;
[PublicAPI]
public record struct ConfigureStripeAccountRequest(
Guid SubscriptionId,
string StripeAccountId);
public class ConfigureStripeAccountHandler(
MembershipDbContext dbContext,
StripeService stripeService)
: Endpoint<ConfigureStripeAccountRequest>
{
public override void Configure()
{
Post("/api/membership/stripe-account");
Options(o => o.WithTags("Memberships"));
}
public override async Task HandleAsync(
ConfigureStripeAccountRequest req,
CancellationToken ct)
{
var creatorId = HttpContext.User.GetUserId();
var creator = await dbContext
.Creators
.FindAsync(
[creatorId],
cancellationToken: ct);
if (creator is null)
{
creator = new Creator
{
Id = creatorId,
Name = HttpContext.User.GetAlias() ?? creatorId.ToString()
};
await dbContext.AddAsync(creator, ct);
}
creator.StripeAccountId = req.StripeAccountId;
await dbContext.SaveChangesAsync(ct);
await SendOkAsync(creator.Id, ct);
}
}