Реализован модуль каталога, миграции, сваггер

This commit is contained in:
Халимов Рустам
2026-02-10 15:32:40 +03:00
parent 4c9e44e992
commit 9d3999f690
40 changed files with 1665 additions and 4 deletions
@@ -0,0 +1,38 @@
using System.Text.Json;
using MediatR;
using Nashel.Modules.Catalog.Application.Common;
using Nashel.Modules.Catalog.Domain.Repositories;
namespace Nashel.Modules.Catalog.Application.Queries;
/// <summary>
/// Запрос дерева категорий.
/// </summary>
public record GetCategoriesQuery() : IRequest<List<CategoryDto>>;
public class GetCategoriesQueryHandler : IRequestHandler<GetCategoriesQuery, List<CategoryDto>>
{
private readonly ICategoryRepository _repository;
public GetCategoriesQueryHandler(ICategoryRepository repository)
{
_repository = repository;
}
public async Task<List<CategoryDto>> Handle(GetCategoriesQuery request, CancellationToken cancellationToken)
{
var rawCategories = await _repository.GetAllAsync(cancellationToken);
// Преобразование в DTO (для дерева логика нужна сложнее, но пока плоский список для старта)
// Если нужно дерево: нужно иметь DTO с List<CategoryDto> Children
// Для MVP возвращаем плоский список, фронтенд сам строит дерево по ParentId
return rawCategories.Select(c => new CategoryDto(
c.Id,
c.Title,
c.Slug,
c.ParentId,
c.AttributeSchema
)).ToList();
}
}
@@ -0,0 +1,37 @@
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
);
}
}