Files
social-media/src/Web/Features/Contents/Handlers/GetFollowedCreators.cs
Jonathan Bourdon 28d74503df + Tips
+ Memberships
- DDD
- FutureCreator
- UserTransactions
2024-10-20 15:48:42 -04:00

35 lines
934 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 GetFollowedCreatorsHandler(
ContentDbContext context)
: EndpointWithoutRequest<List<FollowModel>>
{
public override void Configure()
{
Get("/api/creators/followed");
Options((o => o.WithTags("Creators")));
}
public override async Task HandleAsync(
CancellationToken ct)
{
var userId = HttpContext.User.GetUserId();
var subscriptions = await context
.Followers
.Where(s => s.CreatedBy == userId)
.Select(s => new FollowModel(
s.CreatorId,
s.Creator!.Name,
s.Creator.Images.Logo))
.ToListAsync(cancellationToken: ct);
await SendOkAsync(subscriptions, ct);
}
}