83f51c6a23
Added shopping cart and items Added quotes Refactored relatinoships Migrated changes Refactored cqrs commands and queries Refactored mappings
27 lines
1010 B
C#
27 lines
1010 B
C#
using LiteCharms.Extensions;
|
|
using LiteCharms.Infrastructure.Database;
|
|
using LiteCharms.Models;
|
|
|
|
namespace LiteCharms.Features.Refunds.Queries.Handlers;
|
|
|
|
public class GetRefundQueryHandler(IDbContextFactory<LeadGeneratorDbContext> contextFactory) : IRequestHandler<GetRefundQuery, Result<OrderRefund>>
|
|
{
|
|
public async ValueTask<Result<OrderRefund>> Handle(GetRefundQuery request, CancellationToken cancellationToken)
|
|
{
|
|
try
|
|
{
|
|
using var context = await contextFactory.CreateDbContextAsync(cancellationToken);
|
|
|
|
var refund = await context.OrderRefunds.AsNoTracking().FirstOrDefaultAsync(r => r.Id == request.OrderRefundId, cancellationToken);
|
|
|
|
return refund is not null
|
|
? Result.Ok(refund.ToModel())
|
|
: Result.Fail<OrderRefund>($"Order refund could not be found with id {request.OrderRefundId}");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return Result.Fail<OrderRefund>(new Error(ex.Message).CausedBy(ex));
|
|
}
|
|
}
|
|
}
|