31 lines
797 B
C#
31 lines
797 B
C#
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);
|
|
}
|
|
}
|