Infrastructure

This commit is contained in:
2026-04-22 20:51:02 +04:30
parent c64c3dd9be
commit 64ee78e320
199 changed files with 7428 additions and 1027 deletions
@@ -0,0 +1,18 @@
using Vizhvizh.BuildingBlocks.Application.Configuration.Commnad;
using Vizhvizh.GoldGallery.ApplicationContract.Commands;
using Vizhvizh.GoldGallery.Domain.Products.Entities;
using Vizhvizh.GoldGallery.Domain.Products.Repositories;
namespace Vizhvizh.GoldGallery.Application.CommandHandlers.Categories;
public class CreateCategoryCommandHandler(ICategoryRepository categoryRepository) : ICommandHandler<CreateCategoryCommand>
{
public Task Handle(CreateCategoryCommand request, CancellationToken cancellationToken)
{
//var category = Category.CreateNew(request.Title,
// request.Description,
// request.Image)
throw new Exception();
}
}
@@ -0,0 +1,38 @@
using FluentValidation;
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;
using Vizhvizh.GoldGallery.Domain.Resource.Products;
namespace Vizhvizh.GoldGallery.Application.CommandHandlers.Products;
public class CreateProductCommandHandler(IProductRepository productRepository,
ICategoryRepository categoryRepository) : ICommandHandler<CreateProductCommand>
{
public async Task Handle(CreateProductCommand request, CancellationToken cancellationToken)
{
var category = (await categoryRepository.FindByIdAsync(request.CategoryId, cancellationToken))!;
var specifications = request.ProductSpecifications.Select(x => Specifications.CreateNew(x.Title, x.Values)).ToList();
var productVariantImage = request.ProductVariants.Select(x => x.Gallery).ToList();
var productVariants = request.ProductVariants.Select(x => ProductVariant.CreateNew(x.Quantity, x.Weight, x.Gallery)).ToList();
var product = Product.CreateNew(request.Title, request.Description,
request.ProductCondition, category, specifications, productVariants, request.Image, request.File3D, request.CraftsmanshipFee);
await productRepository.AddAsync(product, cancellationToken);
}
}
public class CreateProductCommandValidator : AbstractValidator<CreateProductCommand>
{
public CreateProductCommandValidator(ICategoryRepository categoryRepository)
{
RuleFor(x => x.CategoryId)
.MustAsync(async (id, cancellation) =>
{
return await categoryRepository.GetQueryAsNoTracking().AnyAsync(x => x.Id == id);
}).WithMessage(m => string.Format(ValidationResources.NotFoundCategoryById, m.CategoryId));
}
}
@@ -0,0 +1,33 @@
using Vizhvizh.BuildingBlocks.Application.Configuration.Commnad;
using Vizhvizh.Shared.Domain.ValueObjects;
using Vizhvizh.GoldGallery.ApplicationContract.Commands;
using Vizhvizh.GoldGallery.Domain.Shops.Repositories;
using Vizhvizh.GoldGallery.Domain.Shops.TypeIds;
using Vizhvizh.GoldGallery.Domain.Shops.ValuesObjects;
using FluentValidation;
namespace Vizhvizh.GoldGallery.Application.CommandHandlers.Shops;
public class CreateShopCommandHandler(IShopRepository shopRepository) : ICommandHandler<CreateShopCommand>
{
public async Task Handle(CreateShopCommand request, CancellationToken cancellationToken)
{
var location = ShopLocation.CreateNew(request.ShopLocation.Latitude, request.ShopLocation.Longitude,
request.ShopLocation.ProvinceId, request.ShopLocation.CityId, request.ShopLocation.Address, request.ShopLocation.PostalCode);
var businessLicense = ShopBusinessLicense.CreateNew(request.ShopBusinessLicenseImage, request.ShopBusinessLicenseCode);
var shop = Domain.Shops.Entities.Shop.CreateNew(request.OwnerId, request.Title,
location, TelephoneVO.CreateNew(request.Telephone), businessLicense, request.Description);
await shopRepository.AddAsync(shop, cancellationToken);
}
}
public class CreateShopCommandValidator : AbstractValidator<CreateShopCommand>
{
public CreateShopCommandValidator()
{
}
}
@@ -0,0 +1,14 @@
using Vizhvizh.BuildingBlocks.Application.Configuration.Commnad;
using Vizhvizh.GoldGallery.ApplicationContract.Commands;
using Vizhvizh.GoldGallery.Domain.Shops.Repositories;
namespace Vizhvizh.GoldGallery.Application.CommandHandlers.Shops;
public class SetTitleShopCommandHandler(IShopRepository shopRepository) : ICommandHandler<SetTitleShopCommand>
{
public async Task Handle(SetTitleShopCommand request, CancellationToken cancellationToken)
{
var shop = await shopRepository.FindByIdAsync(request.ShopId, cancellationToken);
shop.SetTitle(request.Title);
}
}
@@ -0,0 +1,18 @@
using Vizhvizh.BuildingBlocks.Application.Configuration.Commnad;
using Vizhvizh.GoldGallery.ApplicationContract.Commands;
using Vizhvizh.GoldGallery.Domain.Sliders.Entities;
using Vizhvizh.GoldGallery.Domain.Sliders.Repositories;
using Vizhvizh.GoldGallery.Domain.Sliders.ValuesObjects;
namespace Vizhvizh.GoldGallery.Application.CommandHandlers.Sliders;
public class CreateSliderCommandHandler(ISliderRepository sliderRepository) : ICommandHandler<CreateSliderCommand>
{
public async Task Handle(CreateSliderCommand request, CancellationToken cancellationToken)
{
var slider = Slider.CreateNew(request.Title, SliderImage.CreateNew(request.ImageUrl),
SliderUrl.CreateNew(request.LinkUrl), new SliderKey(request.SliderKeyType, request.SliderKey));
await sliderRepository.AddAsync(slider, cancellationToken);
}
}
@@ -0,0 +1,22 @@
using FluentValidation;
using Vizhvizh.BuildingBlocks.Application.Configuration.Commnad;
using Vizhvizh.GoldGallery.ApplicationContract.Commands;
namespace Vizhvizh.GoldGallery.Application.CommandHandlers
{
public class TestCommandHandler : ICommandHandler<TestCommand, Guid>
{
public Task<Guid> Handle(TestCommand request, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
}
public class TestCommandValidator : AbstractValidator<TestCommand>
{
public TestCommandValidator()
{
}
}
}
@@ -0,0 +1,13 @@
using Vizhvizh.BuildingBlocks.Application.Contract;
using Vizhvizh.BuildingBlocks.Domain.Contract;
namespace Vizhvizh.GoldGallery.Application;
public interface IGoldGalleryModule
{
Task<TResult> ExecuteCommandAsync<TResult>(ICommand<TResult> command,CancellationToken cancellationToken);
Task ExecuteCommandAsync(ICommand command, CancellationToken cancellationToken);
Task<TResult> ExecuteQueryAsync<TResult>(IQuery<TResult> query, CancellationToken cancellationToken);
}
@@ -0,0 +1,33 @@
using Dapper;
using Vizhvizh.BuildingBlocks.Application.Configuration.Query;
using Vizhvizh.BuildingBlocks.Application.Data;
using Vizhvizh.BuildingBlocks.Application.SelectBuilders;
using Vizhvizh.GoldGallery.ApplicationContract.DTOs;
using Vizhvizh.GoldGallery.ApplicationContract.Queries;
namespace Vizhvizh.GoldGallery.Application.QueryHandlers.Shops;
public class GetShopByIdQueryHandler(ISqlConnectionFactory connectionFactory, ISqlSelectBuilder sqlSelectBuilder) : IQueryHandler<GetShopByIdQuery, ShopDTO?>
{
public async Task<ShopDTO?> Handle(GetShopByIdQuery request, CancellationToken cancellationToken)
{
var connection = connectionFactory.GetOpenConnection();
var (sql, parameters) = sqlSelectBuilder
.From("Shop.Shops")
.Select<Domain.Shops.Entities.Shop, ShopDTO>(
(d => d.Id, dto => dto.Id),
(d => d.OwnerId, dto => dto.OwnerId),
(d => d.Title, dto => dto.Title),
(d => d.Description, dto => dto.Description),
(d => d.Email, dto => dto.Email),
(d => d.Telephone, dto => dto.Telephone),
(d => d.Logo, dto => dto.Logo)
)
.Where<ShopDTO>(s => s.Id, request.ShopId)
.Build();
var result = await connection.QueryFirstOrDefaultAsync<ShopDTO>(sql, parameters);
return result;
}
}
@@ -0,0 +1,31 @@
using Dapper;
using Vizhvizh.BuildingBlocks.Application.Configuration.Query;
using Vizhvizh.BuildingBlocks.Application.Data;
using Vizhvizh.BuildingBlocks.Application.SelectBuilders;
using Vizhvizh.GoldGallery.ApplicationContract.DTOs;
using Vizhvizh.GoldGallery.ApplicationContract.Queries;
using Vizhvizh.GoldGallery.Domain.Sliders.Entities;
namespace Vizhvizh.GoldGallery.Application.QueryHandlers.Sliders;
public class GetSlidersByKeyQueryHandler(ISqlConnectionFactory sqlConnectionFactory, ISqlSelectBuilder sqlSelectBuilder)
: IQueryHandler<GetSlidersByKeyQuery, IEnumerable<SliderDTO>>
{
public async Task<IEnumerable<SliderDTO>> Handle(GetSlidersByKeyQuery request, CancellationToken cancellationToken)
{
var connection = sqlConnectionFactory.GetOpenConnection();
var (sql, parameters) = sqlSelectBuilder.From("Shop.Sliders")
.Select<Slider, SliderDTO>(
(d => d.Title, dto => dto.Title),
(d => d.Image, dto => dto.Image),
(d => d.Url, dto => dto.LinkUrl)
)
.Pagination<Slider>(request.PageNumber, request.PageSize, x => x.CreateOn, false)
.Where<Slider>(x => x.Key, request.Key)
.Build();
var result = await connection.QueryAsync<SliderDTO>(sql, parameters);
return result;
}
}
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Dapper" Version="2.1.72" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Vizhvizh.GoldGallery.ApplicationContract\Vizhvizh.GoldGallery.ApplicationContract.csproj" />
</ItemGroup>
</Project>