Added shared projects

This commit is contained in:
Khwezi Mngoma
2026-05-03 16:10:27 +02:00
parent 66c08dc54b
commit 1b997013bb
81 changed files with 4507 additions and 1 deletions
@@ -0,0 +1,27 @@
using LiteCharms.Extensions;
using LiteCharms.Infrastructure.Database;
using LiteCharms.Models;
namespace LiteCharms.Features.Orders.Queries.Handlers;
public class GetOrderRefundQueryHandler(IDbContextFactory<LeadGeneratorDbContext> contextFactory) : IRequestHandler<GetOrderRefundQuery, Result<OrderRefund>>
{
public async ValueTask<Result<OrderRefund>> Handle(GetOrderRefundQuery request, CancellationToken cancellationToken)
{
try
{
using var context = await contextFactory.CreateDbContextAsync(cancellationToken);
var refund = await context.OrderRefunds.AsNoTracking()
.FirstOrDefaultAsync(r => r.OrderId == request.OrderId && r.Id == request.OrderRefundId, cancellationToken);
return refund is not null
? Result.Ok(refund.ToModel())
: Result.Fail<OrderRefund>(new Error($"Refund {request.OrderRefundId} not found for the given OrderId: {request.OrderId}"));
}
catch (Exception ex)
{
return Result.Fail<OrderRefund>(new Error(ex.Message).CausedBy(ex));
}
}
}