Files
social-media/src/Web/Features/Contents/Handlers/GetSubscriptions.cs

35 lines
943 B
C#

using Hutopy.Web.Common;
using Hutopy.Web.Features.Contents.Data;
using Hutopy.Web.Features.Contents.Handlers.Models;
namespace Hutopy.Web.Features.Contents.Handlers;
[PublicAPI]
public class GetSubscriptionsHandler(
ContentDbContext context)
: EndpointWithoutRequest<List<SubscriptionModel>>
{
public override void Configure()
{
Get("/api/subscriptions");
Options((o => o.WithTags("Creators")));
}
public override async Task HandleAsync(
CancellationToken ct)
{
var userId = HttpContext.User.GetUserId();
var subscriptions = await context
.Subscriptions
.Where(s => s.CreatedBy == userId)
.Select(s => new SubscriptionModel(
s.CreatorId,
s.Creator!.Name,
s.Creator.Images.Logo))
.ToListAsync(cancellationToken: ct);
await SendOkAsync(subscriptions, ct);
}
}