44 lines
1.3 KiB
C#
44 lines
1.3 KiB
C#
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 = !string.IsNullOrWhiteSpace(eventModel.StripeAccountId);
|
|
|
|
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);
|
|
}
|
|
}
|
|
}
|