Files
nashel-backend/src/Modules/Catalog/Application/Queries/GetOfferByIdQuery.cs

38 lines
1.0 KiB
C#

using MediatR;
using Nashel.Modules.Catalog.Application.Common;
using Nashel.Modules.Catalog.Domain.Repositories;
namespace Nashel.Modules.Catalog.Application.Queries;
/// <summary>
/// Запрос деталей услуги по ID.
/// </summary>
public record GetOfferByIdQuery(Guid Id) : IRequest<OfferDto?>;
public class GetOfferByIdQueryHandler : IRequestHandler<GetOfferByIdQuery, OfferDto?>
{
private readonly IOfferRepository _repository;
public GetOfferByIdQueryHandler(IOfferRepository repository)
{
_repository = repository;
}
public async Task<OfferDto?> Handle(GetOfferByIdQuery request, CancellationToken cancellationToken)
{
var offer = await _repository.GetByIdAsync(request.Id, cancellationToken);
if (offer == null) return null;
return new OfferDto(
offer.Id,
offer.OwnerId,
offer.CategoryId,
offer.Title,
offer.Description,
offer.Price,
offer.Attributes,
offer.IsActive
);
}
}