This commit is contained in:
2026-04-22 22:37:31 +04:30
parent 15d11122b8
commit 6d35ef772c
8 changed files with 45 additions and 16 deletions
@@ -1,4 +1,5 @@
using Vizhvizh.BuildingBlocks.Application.Configuration.Commnad;
using Microsoft.EntityFrameworkCore;
using Vizhvizh.BuildingBlocks.Application.Configuration.Commnad;
using Vizhvizh.GoldGallery.ApplicationContract.Commands;
using Vizhvizh.GoldGallery.Domain.Products.Entities;
using Vizhvizh.GoldGallery.Domain.Products.Repositories;
@@ -10,10 +11,24 @@ public class CreateCategoryCommandHandler(ICategoryRepository categoryRepository
{
public async Task Handle(CreateCategoryCommand request, CancellationToken cancellationToken)
{
CategoryPath? parentPath = null;
if(request.ParentId != null)
{
parentPath = await categoryRepository.GetQueryAsNoTracking()
.Where(x => x.Id == request.ParentId)
.Select(x => x.Path)
.FirstOrDefaultAsync(cancellationToken);
}
var category = Category.CreateNew(request.Title,
request.Description,
request.Image, CategoryPath.CreateNew("/1/"));
request.Image,
request.ParentId);
await categoryRepository.AddAsync(category, cancellationToken);
category.SetPath(parentPath);
}
}