Hold on Subscriptions

This commit is contained in:
Jonathan Bourdon
2024-08-03 22:56:12 -04:00
parent 2b30e1a03c
commit 0340904847
7 changed files with 103 additions and 9 deletions

View File

@@ -0,0 +1,30 @@
using FastEndpoints;
using Hutopy.Web.Common;
using Hutopy.Web.Features.Contents.Data;
namespace Hutopy.Web.Features.Contents.Handlers;
public record SubscribeToCreatorRequest(
Guid CreatorId);
public sealed class SubscribeToCreatorHandler(
ContentDbContext context)
: Endpoint<UnsubscribeFromCreatorRequest>
{
public override void Configure()
{
Post("/api/creators/{CreatorId}/subscribe");
Options((o => o.WithTags("Creators")));
}
public override async Task HandleAsync(
UnsubscribeFromCreatorRequest req,
CancellationToken ct)
{
await context.Subscriptions.AddAsync(
new() { CreatedBy = HttpContext.User.GetUserId(), CreatorId = req.CreatorId },
ct);
await SendOkAsync(ct);
}
}