44 lines
1.1 KiB
C#
44 lines
1.1 KiB
C#
using Hutopy.Web.Common;
|
|
using Hutopy.Web.Features.Contents.Data;
|
|
|
|
namespace Hutopy.Web.Features.Contents.Handlers;
|
|
|
|
[PublicAPI]
|
|
public sealed class UnsubscribeFromCreatorRequest
|
|
{
|
|
public Guid CreatorId { get; set; }
|
|
}
|
|
|
|
[PublicAPI]
|
|
public class UnsubscribeFromCreatorHandler(
|
|
ContentDbContext context)
|
|
: Endpoint<UnsubscribeFromCreatorRequest>
|
|
{
|
|
public override void Configure()
|
|
{
|
|
Post("/api/creators/{CreatorId}/unsubscribe");
|
|
Options((o => o.WithTags("Subscriptions")));
|
|
Description(x => x.Accepts<string>("*/*"));
|
|
}
|
|
|
|
public override async Task HandleAsync(
|
|
UnsubscribeFromCreatorRequest req,
|
|
CancellationToken ct)
|
|
{
|
|
var subscription = new Subscription { CreatorId = req.CreatorId, CreatedBy = HttpContext.User.GetUserId() };
|
|
|
|
context.Subscriptions.Attach(subscription);
|
|
context.Subscriptions.Remove(subscription);
|
|
|
|
try
|
|
{
|
|
await context.SaveChangesAsync(ct);
|
|
await SendOkAsync(ct);
|
|
}
|
|
catch (Exception)
|
|
{
|
|
await SendNotFoundAsync(ct);
|
|
}
|
|
}
|
|
}
|