Реализован модуль каталога, миграции, сваггер
This commit is contained in:
@@ -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
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user