diff --git a/backend/src/Web/Features/Contents/Handlers/CreateCreator.cs b/backend/src/Web/Features/Contents/Handlers/CreateCreator.cs index a9e6bb1..83ae15c 100644 --- a/backend/src/Web/Features/Contents/Handlers/CreateCreator.cs +++ b/backend/src/Web/Features/Contents/Handlers/CreateCreator.cs @@ -48,7 +48,7 @@ public sealed class CreateCreatorHandler( .Slugs .SingleAsync(s => s.Id == req.SlugReservationId, ct); - if (slug.Active == true + if (slug.Active || slug.ReservedUntil < DateTimeOffset.UtcNow || slug.CreatedBy != User.GetUserId()) { diff --git a/backend/src/Web/Features/Contents/Handlers/RemoveCreator.cs b/backend/src/Web/Features/Contents/Handlers/RemoveCreator.cs new file mode 100644 index 0000000..a5020fc --- /dev/null +++ b/backend/src/Web/Features/Contents/Handlers/RemoveCreator.cs @@ -0,0 +1,66 @@ +using Hutopy.Web.Common.Security; +using Hutopy.Web.Features.Contents.Data; + +namespace Hutopy.Web.Features.Contents.Handlers; + +[PublicAPI] +public record RemoveCreatorRequest( + Guid CreatorId); + +[UsedImplicitly] +public sealed class RemoveCreatorRequestValidator : Validator +{ + public RemoveCreatorRequestValidator() + { + RuleFor(r => r.CreatorId) + .NotNull() + .NotEmpty() + .WithMessage("You should specify a valid CreatorId"); + } +} + +[PublicAPI] +public sealed class RemoveCreatorHandler( + ContentDbContext context) + : Endpoint +{ + public override void Configure() + { + Delete("/api/creators"); + Options(o => o.WithTags("Creators")); + } + + public override async Task HandleAsync( + RemoveCreatorRequest req, + CancellationToken ct) + { + await using var transaction = await context.Database.BeginTransactionAsync(ct); + + try + { + var creator = await context + .Creators + .Include(c => c.Slugs) + .Where(c => c.Id == req.CreatorId) + .SingleOrDefaultAsync(cancellationToken: ct); + + if (creator is null) + { + await SendNotFoundAsync(ct); + return; + } + + creator.Slugs.Active = false; + + await context.SaveChangesAsync(ct); + + await transaction.CommitAsync(ct); + + await SendOkAsync(ct); + } + catch (Exception e) + { + await transaction.RollbackAsync(ct); + } + } +} diff --git a/backend/src/Web/appsettings.Development.json b/backend/src/Web/appsettings.Development.json index 538fd47..fee981d 100644 --- a/backend/src/Web/appsettings.Development.json +++ b/backend/src/Web/appsettings.Development.json @@ -1,15 +1,6 @@ { "ConnectionStrings": { - "AzureBlob": "DefaultEndpointsProtocol=https;AccountName=hutopyblob;AccountKey=AjK9vQMCIAG280PFIAWDjTtiFc/fIj/fb1NA9xtC7SLm6ZMZa/Agg0JFGYcHuJEaoZKDme7mNx/U+AStt9o7LQ==;EndpointSuffix=core.windows.net", - "PostgresConnection": "Server=localhost,5432;Database=Hutopy;Uid=sa;Pwd=P@ssword123!;", - }, - "Authentication": { - "Jwt": { - "Lifetime": "1.00:00:00", - "Audience": "hutopy", - "Issuer": "https://auth.hutopy.com", - "Key": "b2df428b9929d3ace7c598bbf4e496b2f0b71ab3cd4f94540356cfc35b000000" - } + "PostgresConnection": "Server=localhost,5432;Database=Hutopy;Uid=sa;Pwd=P@ssword123!;" }, "Stripe": { "SecretKey": "sk_test_51OoveVDrRyqXtNdBaOs1DFFja0XhrQtJoAo83uSySMuqw4Wyt9NsuugrIHRqet9a50cr5GvolpTP8EZuTSttcgYx00gOUPNDoI", diff --git a/backend/src/Web/appsettings.Production.json b/backend/src/Web/appsettings.Production.json index 71ad1d9..ab0a4c9 100644 --- a/backend/src/Web/appsettings.Production.json +++ b/backend/src/Web/appsettings.Production.json @@ -1,16 +1,7 @@ { "ConnectionStrings": { - "AzureBlob": "DefaultEndpointsProtocol=https;AccountName=hutopyblob;AccountKey=AjK9vQMCIAG280PFIAWDjTtiFc/fIj/fb1NA9xtC7SLm6ZMZa/Agg0JFGYcHuJEaoZKDme7mNx/U+AStt9o7LQ==;EndpointSuffix=core.windows.net", "PostgresConnection": "Server=hutopypostgress.postgres.database.azure.com,5432;Database=hutopy;User Id=hutopy;Password=General2024!;Ssl Mode=Require;" }, - "Authentication": { - "Jwt": { - "Lifetime": "1.00:00:00", - "Audience": "hutopy", - "Issuer": "https://auth.hutopy.com", - "Key": "b2df428b9929d3ace7c598bbf4e496b2f0b71ab3cd4f94540356cfc35b000000" - } - }, "Stripe": { "SecretKey": "sk_test_51OoveVDrRyqXtNdBaOs1DFFja0XhrQtJoAo83uSySMuqw4Wyt9NsuugrIHRqet9a50cr5GvolpTP8EZuTSttcgYx00gOUPNDoI", "WebhookSecret": "whsec_cee07ef14cf784850cab63567048b5326fec7fd29c03f4659476524f8299aff1", diff --git a/backend/src/Web/appsettings.json b/backend/src/Web/appsettings.json index 3ee0362..feae649 100644 --- a/backend/src/Web/appsettings.json +++ b/backend/src/Web/appsettings.json @@ -8,9 +8,15 @@ } }, "AllowedHosts": "*", + "ConnectionStrings": { + "AzureBlob": "DefaultEndpointsProtocol=https;AccountName=hutopystorage;AccountKey=+3LZ3fgVvsOtaM9iYcsUhSyT2GZT4I6AQegE1FyIqr8NMv5Qa4Fm8GspckP/DCFN3jbFI8TnTLXY+AStWjvCkg==;EndpointSuffix=core.windows.net" + }, "Authentication": { "Jwt": { - "Lifetime": "00:30:00" + "Lifetime": "00:30:00", + "Audience": "hutopy", + "Issuer": "https://auth.hutopy.com", + "Key": "b2df428b9929d3ace7c598bbf4e496b2f0b71ab3cd4f94540356cfc35b000000" } }, "Contents": {