many fixes and improvements - rework for modules/ and common/
feat(emailer): add Postmark and Resend providers
This commit is contained in:
49
backend/Modules/Tipping/Handlers/GetReceivedTips.cs
Normal file
49
backend/Modules/Tipping/Handlers/GetReceivedTips.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
using Hutopy.Infrastructure.Security;
|
||||
using Hutopy.Modules.Identity.Contracts;
|
||||
using Hutopy.Modules.Tipping.Data;
|
||||
using Hutopy.Modules.Tipping.Models;
|
||||
|
||||
namespace Hutopy.Modules.Tipping.Handlers;
|
||||
|
||||
[PublicAPI]
|
||||
public record struct GetReceivedTipsResponse(
|
||||
IEnumerable<TipReceivedModel> Tips);
|
||||
|
||||
[PublicAPI]
|
||||
public class GetReceivedTipsHandler(
|
||||
IUserLookup userLookup,
|
||||
TippingDbContext dbContext)
|
||||
: EndpointWithoutRequest<GetReceivedTipsResponse>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Get("/api/tips");
|
||||
Options(o => o.WithTags("Tips"));
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(
|
||||
CancellationToken ct)
|
||||
{
|
||||
var tips = await dbContext
|
||||
.Tips
|
||||
.Where(tip => tip.CreatorId == User.GetUserId())
|
||||
.ToListAsync(ct);
|
||||
|
||||
var result = await Task.WhenAll(
|
||||
tips.Select(async tip =>
|
||||
{
|
||||
var tipper = await userLookup.GetUserAsync(tip.CreatorId, ct);
|
||||
|
||||
return new TipReceivedModel(
|
||||
tip.Id,
|
||||
tip.CreatedAt,
|
||||
tip.CreatedBy,
|
||||
tipper?.Fullname ?? "Unknown User",
|
||||
tip.Amount,
|
||||
tip.Currency,
|
||||
tip.Message);
|
||||
}));
|
||||
|
||||
await SendOkAsync(new GetReceivedTipsResponse(result), ct);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user