Hold on Subscriptions
This commit is contained in:
@@ -28,7 +28,7 @@ public class GetCreatorByAliasHandler(
|
||||
public override void Configure()
|
||||
{
|
||||
Get("/api/creators/@{Name}");
|
||||
Options((o => o.WithTags("Creators")));
|
||||
Options((o => o.WithTags("Contents")));
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ public class GetCreatorByIdHandler(
|
||||
public override void Configure()
|
||||
{
|
||||
Get("/api/creators/{CreatorId}");
|
||||
Options((o => o.WithTags("Creators")));
|
||||
Options((o => o.WithTags("Contents")));
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
|
||||
31
src/Web/Features/Contents/Handlers/GetSubscriptions.cs
Normal file
31
src/Web/Features/Contents/Handlers/GetSubscriptions.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using FastEndpoints;
|
||||
using Hutopy.Web.Common;
|
||||
using Hutopy.Web.Features.Contents.Data;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Hutopy.Web.Features.Contents.Handlers;
|
||||
|
||||
public class GetSubscriptionsHandler(
|
||||
ContentDbContext context)
|
||||
: EndpointWithoutRequest
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Get("/api/subscriptions");
|
||||
Options((o => o.WithTags("Creators")));
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(
|
||||
CancellationToken ct)
|
||||
{
|
||||
var userId = HttpContext.User.GetUserId();
|
||||
|
||||
await context
|
||||
.Subscriptions
|
||||
.Where(s => s.CreatedBy == userId)
|
||||
.Include(s => s.Creator)
|
||||
.ToListAsync(cancellationToken: ct);
|
||||
|
||||
await SendOkAsync(ct);
|
||||
}
|
||||
}
|
||||
21
src/Web/Features/Contents/Handlers/SubscripbeFromCreator.cs
Normal file
21
src/Web/Features/Contents/Handlers/SubscripbeFromCreator.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using FastEndpoints;
|
||||
|
||||
namespace Hutopy.Web.Features.Contents.Handlers;
|
||||
|
||||
public record UnsubscribeFromCreatorRequest(
|
||||
Guid CreatorId);
|
||||
|
||||
public class UnsubscribeFromCreatorHandler
|
||||
: Endpoint<UnsubscribeFromCreatorRequest>
|
||||
{ public override void Configure()
|
||||
{
|
||||
Post("");
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(
|
||||
UnsubscribeFromCreatorRequest req,
|
||||
CancellationToken ct)
|
||||
{
|
||||
return base.HandleAsync(req, ct);
|
||||
}
|
||||
}
|
||||
30
src/Web/Features/Contents/Handlers/SubscripbeToCreator.cs
Normal file
30
src/Web/Features/Contents/Handlers/SubscripbeToCreator.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user