Услуги

This commit is contained in:
Халимов Рустам
2026-03-05 15:24:33 +03:00
parent 36e7c07a0d
commit e41692a6e2
31 changed files with 963 additions and 102 deletions
@@ -0,0 +1,45 @@
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;
/// <summary>
/// Запрос получения услуг текущего пользователя.
/// </summary>
public record GetMyOffersQuery() : IRequest<Result<List<OfferDto>>>;
public class GetMyOffersQueryHandler : IRequestHandler<GetMyOffersQuery, Result<List<OfferDto>>>
{
private readonly IOfferRepository _repository;
private readonly ICurrentUserService _currentUserService;
public GetMyOffersQueryHandler(IOfferRepository repository, ICurrentUserService currentUserService)
{
_repository = repository;
_currentUserService = currentUserService;
}
public async Task<Result<List<OfferDto>>> Handle(GetMyOffersQuery request, CancellationToken cancellationToken)
{
var userId = _currentUserService.UserId;
if (userId == null) return Result<List<OfferDto>>.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
)).ToList();
return Result<List<OfferDto>>.Success(list);
}
}