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

46 lines
1.1 KiB
C#

using Hutopy.Web.Common;
using Hutopy.Web.Features.Memberships.Data;
namespace Hutopy.Web.Features.Memberships.Handlers;
[PublicAPI]
public record struct TipSentModel(
Guid Id,
DateTimeOffset CreatedAt,
Guid CreatorId,
string CreatorName,
decimal Amount,
string Currency,
string Message);
[PublicAPI]
public class GetSentTipsHandler(
MembershipDbContext dbContext)
: EndpointWithoutRequest<List<TipSentModel>>
{
public override void Configure()
{
Get("/api/tips/sent");
Options(o => o.WithTags("Memberships"));
}
public override async Task HandleAsync(
CancellationToken ct)
{
var tips = await dbContext
.Tips
.Where(t => t.TipperId == User.GetUserId())
.Select(tip => new TipSentModel(
tip.Id,
tip.CreatedAt,
tip.CreatorId,
tip.CreatorName,
tip.Amount,
tip.Currency,
tip.Message))
.ToListAsync(ct);
await SendOkAsync(tips, ct);
}
}