Услуги

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
@@ -1,5 +1,6 @@
using System.Text.Json;
using MediatR;
using Nashel.BuildingBlocks.Domain;
using Nashel.Modules.Catalog.Application.Common;
using Nashel.Modules.Catalog.Domain.Repositories;
@@ -8,9 +9,9 @@ namespace Nashel.Modules.Catalog.Application.Queries;
/// <summary>
/// Запрос дерева категорий.
/// </summary>
public record GetCategoriesQuery() : IRequest<List<CategoryDto>>;
public record GetCategoriesQuery() : IRequest<Result<List<CategoryDto>>>;
public class GetCategoriesQueryHandler : IRequestHandler<GetCategoriesQuery, List<CategoryDto>>
public class GetCategoriesQueryHandler : IRequestHandler<GetCategoriesQuery, Result<List<CategoryDto>>>
{
private readonly ICategoryRepository _repository;
@@ -19,7 +20,7 @@ public class GetCategoriesQueryHandler : IRequestHandler<GetCategoriesQuery, Lis
_repository = repository;
}
public async Task<List<CategoryDto>> Handle(GetCategoriesQuery request, CancellationToken cancellationToken)
public async Task<Result<List<CategoryDto>>> Handle(GetCategoriesQuery request, CancellationToken cancellationToken)
{
var rawCategories = await _repository.GetAllAsync(cancellationToken);
@@ -27,12 +28,14 @@ public class GetCategoriesQueryHandler : IRequestHandler<GetCategoriesQuery, Lis
// Если нужно дерево: нужно иметь DTO с List<CategoryDto> Children
// Для MVP возвращаем плоский список, фронтенд сам строит дерево по ParentId
return rawCategories.Select(c => new CategoryDto(
var list = rawCategories.Select(c => new CategoryDto(
c.Id,
c.Title,
c.Name,
c.Slug,
c.ParentId,
c.AttributeSchema
)).ToList();
return Result<List<CategoryDto>>.Success(list);
}
}
@@ -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);
}
}
@@ -1,4 +1,5 @@
using MediatR;
using Nashel.BuildingBlocks.Domain;
using Nashel.Modules.Catalog.Application.Common;
using Nashel.Modules.Catalog.Domain.Repositories;
@@ -7,9 +8,9 @@ namespace Nashel.Modules.Catalog.Application.Queries;
/// <summary>
/// Запрос деталей услуги по ID.
/// </summary>
public record GetOfferByIdQuery(Guid Id) : IRequest<OfferDto?>;
public record GetOfferByIdQuery(Guid Id) : IRequest<Result<OfferDto>>;
public class GetOfferByIdQueryHandler : IRequestHandler<GetOfferByIdQuery, OfferDto?>
public class GetOfferByIdQueryHandler : IRequestHandler<GetOfferByIdQuery, Result<OfferDto>>
{
private readonly IOfferRepository _repository;
@@ -18,20 +19,22 @@ public class GetOfferByIdQueryHandler : IRequestHandler<GetOfferByIdQuery, Offer
_repository = repository;
}
public async Task<OfferDto?> Handle(GetOfferByIdQuery request, CancellationToken cancellationToken)
public async Task<Result<OfferDto>> Handle(GetOfferByIdQuery request, CancellationToken cancellationToken)
{
var offer = await _repository.GetByIdAsync(request.Id, cancellationToken);
if (offer == null) return null;
if (offer == null) return Result<OfferDto>.Failure("Offer not found");
return new OfferDto(
var dto = new OfferDto(
offer.Id,
offer.OwnerId,
offer.PerformerId,
offer.CategoryId,
offer.Title,
offer.Description,
offer.Description ?? string.Empty,
offer.Price,
offer.Attributes,
offer.IsActive
);
return Result<OfferDto>.Success(dto);
}
}