using MediatR;
using Nashel.BuildingBlocks.Application.Abstractions;
using Nashel.BuildingBlocks.Domain;
using Nashel.Modules.Catalog.Application.Common;
using Nashel.Modules.Catalog.Domain.Repositories;
namespace Nashel.Modules.Catalog.Application.Queries;
///
/// Запрос получения услуг текущего пользователя.
///
public record GetMyOffersQuery() : IRequest>>;
public class GetMyOffersQueryHandler : IRequestHandler>>
{
private readonly IOfferRepository _repository;
private readonly ICurrentUserService _currentUserService;
public GetMyOffersQueryHandler(IOfferRepository repository, ICurrentUserService currentUserService)
{
_repository = repository;
_currentUserService = currentUserService;
}
public async Task>> Handle(GetMyOffersQuery request, CancellationToken cancellationToken)
{
var userId = _currentUserService.UserId;
if (userId == null) return Result>.Failure("Неавторизован");
var offers = await _repository.GetByPerformerIdAsync(userId.Value, cancellationToken);
var list = offers.Select(offer => new OfferDto(
offer.Id,
offer.PerformerId,
offer.CategoryId,
offer.Title,
offer.Description ?? string.Empty,
offer.Price,
offer.Attributes,
offer.IsActive,
offer.Images
)).ToList();
return Result>.Success(list);
}
}