Generator Changes at 11/12/2025 1:32:03 AM +03:30

This commit is contained in:
masoodafar-web
2025-11-12 02:24:02 +03:30
parent 826ae4589f
commit b27c765731
290 changed files with 30811 additions and 21316 deletions
@@ -0,0 +1,29 @@
namespace CMSMicroservice.Application.ProductsCQ.Commands.CreateNewProducts;
public record CreateNewProductsCommand : IRequest<CreateNewProductsResponseDto>
{
//
public string Title { get; init; }
//
public string Description { get; init; }
//
public string ShortInfomation { get; init; }
//
public string FullInformation { get; init; }
//
public long Price { get; init; }
//
public int Discount { get; init; }
//
public int Rate { get; init; }
//
public string ImagePath { get; init; }
//
public string ThumbnailPath { get; init; }
//
public int SaleCount { get; init; }
//
public int ViewCount { get; init; }
//
public int RemainingCount { get; init; }
}
@@ -0,0 +1,21 @@
using CMSMicroservice.Domain.Events;
namespace CMSMicroservice.Application.ProductsCQ.Commands.CreateNewProducts;
public class CreateNewProductsCommandHandler : IRequestHandler<CreateNewProductsCommand, CreateNewProductsResponseDto>
{
private readonly IApplicationDbContext _context;
public CreateNewProductsCommandHandler(IApplicationDbContext context)
{
_context = context;
}
public async Task<CreateNewProductsResponseDto> Handle(CreateNewProductsCommand request,
CancellationToken cancellationToken)
{
var entity = request.Adapt<Products>();
await _context.Productss.AddAsync(entity, cancellationToken);
entity.AddDomainEvent(new CreateNewProductsEvent(entity));
await _context.SaveChangesAsync(cancellationToken);
return entity.Adapt<CreateNewProductsResponseDto>();
}
}
@@ -0,0 +1,38 @@
namespace CMSMicroservice.Application.ProductsCQ.Commands.CreateNewProducts;
public class CreateNewProductsCommandValidator : AbstractValidator<CreateNewProductsCommand>
{
public CreateNewProductsCommandValidator()
{
RuleFor(model => model.Title)
.NotEmpty();
RuleFor(model => model.Description)
.NotEmpty();
RuleFor(model => model.ShortInfomation)
.NotEmpty();
RuleFor(model => model.FullInformation)
.NotEmpty();
RuleFor(model => model.Price)
.NotNull();
RuleFor(model => model.Discount)
.NotNull();
RuleFor(model => model.Rate)
.NotNull();
RuleFor(model => model.ImagePath)
.NotEmpty();
RuleFor(model => model.ThumbnailPath)
.NotEmpty();
RuleFor(model => model.SaleCount)
.NotNull();
RuleFor(model => model.ViewCount)
.NotNull();
RuleFor(model => model.RemainingCount)
.NotNull();
}
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
{
var result = await ValidateAsync(ValidationContext<CreateNewProductsCommand>.CreateWithOptions((CreateNewProductsCommand)model, x => x.IncludeProperties(propertyName)));
if (result.IsValid)
return Array.Empty<string>();
return result.Errors.Select(e => e.ErrorMessage);
};
}
@@ -0,0 +1,7 @@
namespace CMSMicroservice.Application.ProductsCQ.Commands.CreateNewProducts;
public class CreateNewProductsResponseDto
{
//
public long Id { get; set; }
}
@@ -0,0 +1,7 @@
namespace CMSMicroservice.Application.ProductsCQ.Commands.DeleteProducts;
public record DeleteProductsCommand : IRequest<Unit>
{
//
public long Id { get; init; }
}
@@ -0,0 +1,22 @@
using CMSMicroservice.Domain.Events;
namespace CMSMicroservice.Application.ProductsCQ.Commands.DeleteProducts;
public class DeleteProductsCommandHandler : IRequestHandler<DeleteProductsCommand, Unit>
{
private readonly IApplicationDbContext _context;
public DeleteProductsCommandHandler(IApplicationDbContext context)
{
_context = context;
}
public async Task<Unit> Handle(DeleteProductsCommand request, CancellationToken cancellationToken)
{
var entity = await _context.Productss
.FirstOrDefaultAsync(x => x.Id == request.Id, cancellationToken) ?? throw new NotFoundException(nameof(Products), request.Id);
entity.IsDeleted = true;
_context.Productss.Update(entity);
entity.AddDomainEvent(new DeleteProductsEvent(entity));
await _context.SaveChangesAsync(cancellationToken);
return Unit.Value;
}
}
@@ -0,0 +1,16 @@
namespace CMSMicroservice.Application.ProductsCQ.Commands.DeleteProducts;
public class DeleteProductsCommandValidator : AbstractValidator<DeleteProductsCommand>
{
public DeleteProductsCommandValidator()
{
RuleFor(model => model.Id)
.NotNull();
}
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
{
var result = await ValidateAsync(ValidationContext<DeleteProductsCommand>.CreateWithOptions((DeleteProductsCommand)model, x => x.IncludeProperties(propertyName)));
if (result.IsValid)
return Array.Empty<string>();
return result.Errors.Select(e => e.ErrorMessage);
};
}
@@ -0,0 +1,31 @@
namespace CMSMicroservice.Application.ProductsCQ.Commands.UpdateProducts;
public record UpdateProductsCommand : IRequest<Unit>
{
//
public long Id { get; init; }
//
public string Title { get; init; }
//
public string Description { get; init; }
//
public string ShortInfomation { get; init; }
//
public string FullInformation { get; init; }
//
public long Price { get; init; }
//
public int Discount { get; init; }
//
public int Rate { get; init; }
//
public string ImagePath { get; init; }
//
public string ThumbnailPath { get; init; }
//
public int SaleCount { get; init; }
//
public int ViewCount { get; init; }
//
public int RemainingCount { get; init; }
}
@@ -0,0 +1,22 @@
using CMSMicroservice.Domain.Events;
namespace CMSMicroservice.Application.ProductsCQ.Commands.UpdateProducts;
public class UpdateProductsCommandHandler : IRequestHandler<UpdateProductsCommand, Unit>
{
private readonly IApplicationDbContext _context;
public UpdateProductsCommandHandler(IApplicationDbContext context)
{
_context = context;
}
public async Task<Unit> Handle(UpdateProductsCommand request, CancellationToken cancellationToken)
{
var entity = await _context.Productss
.FirstOrDefaultAsync(x => x.Id == request.Id, cancellationToken) ?? throw new NotFoundException(nameof(Products), request.Id);
request.Adapt(entity);
_context.Productss.Update(entity);
entity.AddDomainEvent(new UpdateProductsEvent(entity));
await _context.SaveChangesAsync(cancellationToken);
return Unit.Value;
}
}
@@ -0,0 +1,40 @@
namespace CMSMicroservice.Application.ProductsCQ.Commands.UpdateProducts;
public class UpdateProductsCommandValidator : AbstractValidator<UpdateProductsCommand>
{
public UpdateProductsCommandValidator()
{
RuleFor(model => model.Id)
.NotNull();
RuleFor(model => model.Title)
.NotEmpty();
RuleFor(model => model.Description)
.NotEmpty();
RuleFor(model => model.ShortInfomation)
.NotEmpty();
RuleFor(model => model.FullInformation)
.NotEmpty();
RuleFor(model => model.Price)
.NotNull();
RuleFor(model => model.Discount)
.NotNull();
RuleFor(model => model.Rate)
.NotNull();
RuleFor(model => model.ImagePath)
.NotEmpty();
RuleFor(model => model.ThumbnailPath)
.NotEmpty();
RuleFor(model => model.SaleCount)
.NotNull();
RuleFor(model => model.ViewCount)
.NotNull();
RuleFor(model => model.RemainingCount)
.NotNull();
}
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
{
var result = await ValidateAsync(ValidationContext<UpdateProductsCommand>.CreateWithOptions((UpdateProductsCommand)model, x => x.IncludeProperties(propertyName)));
if (result.IsValid)
return Array.Empty<string>();
return result.Errors.Select(e => e.ErrorMessage);
};
}
@@ -0,0 +1,22 @@
using CMSMicroservice.Domain.Events;
using Microsoft.Extensions.Logging;
namespace CMSMicroservice.Application.ProductsCQ.EventHandlers;
public class CreateNewProductsEventHandler : INotificationHandler<CreateNewProductsEvent>
{
private readonly ILogger<
CreateNewProductsEventHandler> _logger;
public CreateNewProductsEventHandler(ILogger<CreateNewProductsEventHandler> logger)
{
_logger = logger;
}
public Task Handle(CreateNewProductsEvent notification, CancellationToken cancellationToken)
{
_logger.LogInformation("Domain Event: {DomainEvent}", notification.GetType().Name);
return Task.CompletedTask;
}
}
@@ -0,0 +1,22 @@
using CMSMicroservice.Domain.Events;
using Microsoft.Extensions.Logging;
namespace CMSMicroservice.Application.ProductsCQ.EventHandlers;
public class DeleteProductsEventHandler : INotificationHandler<DeleteProductsEvent>
{
private readonly ILogger<
DeleteProductsEventHandler> _logger;
public DeleteProductsEventHandler(ILogger<DeleteProductsEventHandler> logger)
{
_logger = logger;
}
public Task Handle(DeleteProductsEvent notification, CancellationToken cancellationToken)
{
_logger.LogInformation("Domain Event: {DomainEvent}", notification.GetType().Name);
return Task.CompletedTask;
}
}
@@ -0,0 +1,22 @@
using CMSMicroservice.Domain.Events;
using Microsoft.Extensions.Logging;
namespace CMSMicroservice.Application.ProductsCQ.EventHandlers;
public class UpdateProductsEventHandler : INotificationHandler<UpdateProductsEvent>
{
private readonly ILogger<
UpdateProductsEventHandler> _logger;
public UpdateProductsEventHandler(ILogger<UpdateProductsEventHandler> logger)
{
_logger = logger;
}
public Task Handle(UpdateProductsEvent notification, CancellationToken cancellationToken)
{
_logger.LogInformation("Domain Event: {DomainEvent}", notification.GetType().Name);
return Task.CompletedTask;
}
}
@@ -0,0 +1,39 @@
namespace CMSMicroservice.Application.ProductsCQ.Queries.GetAllProductsByFilter;
public record GetAllProductsByFilterQuery : IRequest<GetAllProductsByFilterResponseDto>
{
//موقعیت صفحه بندی
public PaginationState? PaginationState { get; init; }
//مرتب سازی بر اساس
public string? SortBy { get; init; }
//فیلتر
public GetAllProductsByFilterFilter? Filter { get; init; }
}public class GetAllProductsByFilterFilter
{
//
public long? Id { get; set; }
//
public string? Title { get; set; }
//
public string? Description { get; set; }
//
public string? ShortInfomation { get; set; }
//
public string? FullInformation { get; set; }
//
public long? Price { get; set; }
//
public int? Discount { get; set; }
//
public int? Rate { get; set; }
//
public string? ImagePath { get; set; }
//
public string? ThumbnailPath { get; set; }
//
public int? SaleCount { get; set; }
//
public int? ViewCount { get; set; }
//
public int? RemainingCount { get; set; }
}
@@ -0,0 +1,42 @@
namespace CMSMicroservice.Application.ProductsCQ.Queries.GetAllProductsByFilter;
public class GetAllProductsByFilterQueryHandler : IRequestHandler<GetAllProductsByFilterQuery, GetAllProductsByFilterResponseDto>
{
private readonly IApplicationDbContext _context;
public GetAllProductsByFilterQueryHandler(IApplicationDbContext context)
{
_context = context;
}
public async Task<GetAllProductsByFilterResponseDto> Handle(GetAllProductsByFilterQuery request, CancellationToken cancellationToken)
{
var query = _context.Productss
.ApplyOrder(sortBy: request.SortBy)
.AsNoTracking()
.AsQueryable();
if (request.Filter is not null)
{
query = query
.Where(x => request.Filter.Id == null || x.Id == request.Filter.Id)
.Where(x => request.Filter.Title == null || x.Title.Contains(request.Filter.Title))
.Where(x => request.Filter.Description == null || x.Description.Contains(request.Filter.Description))
.Where(x => request.Filter.ShortInfomation == null || x.ShortInfomation.Contains(request.Filter.ShortInfomation))
.Where(x => request.Filter.FullInformation == null || x.FullInformation.Contains(request.Filter.FullInformation))
.Where(x => request.Filter.Price == null || x.Price == request.Filter.Price)
.Where(x => request.Filter.Discount == null || x.Discount == request.Filter.Discount)
.Where(x => request.Filter.Rate == null || x.Rate == request.Filter.Rate)
.Where(x => request.Filter.ImagePath == null || x.ImagePath.Contains(request.Filter.ImagePath))
.Where(x => request.Filter.ThumbnailPath == null || x.ThumbnailPath.Contains(request.Filter.ThumbnailPath))
.Where(x => request.Filter.SaleCount == null || x.SaleCount == request.Filter.SaleCount)
.Where(x => request.Filter.ViewCount == null || x.ViewCount == request.Filter.ViewCount)
.Where(x => request.Filter.RemainingCount == null || x.RemainingCount == request.Filter.RemainingCount)
;
}
return new GetAllProductsByFilterResponseDto
{
MetaData = await query.GetMetaData(request.PaginationState, cancellationToken),
Models = await query.PaginatedListAsync(paginationState: request.PaginationState)
.ProjectToType<GetAllProductsByFilterResponseModel>().ToListAsync(cancellationToken)
};
}
}
@@ -0,0 +1,14 @@
namespace CMSMicroservice.Application.ProductsCQ.Queries.GetAllProductsByFilter;
public class GetAllProductsByFilterQueryValidator : AbstractValidator<GetAllProductsByFilterQuery>
{
public GetAllProductsByFilterQueryValidator()
{
}
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
{
var result = await ValidateAsync(ValidationContext<GetAllProductsByFilterQuery>.CreateWithOptions((GetAllProductsByFilterQuery)model, x => x.IncludeProperties(propertyName)));
if (result.IsValid)
return Array.Empty<string>();
return result.Errors.Select(e => e.ErrorMessage);
};
}
@@ -0,0 +1,37 @@
namespace CMSMicroservice.Application.ProductsCQ.Queries.GetAllProductsByFilter;
public class GetAllProductsByFilterResponseDto
{
//متادیتا
public MetaData MetaData { get; set; }
//مدل خروجی
public List<GetAllProductsByFilterResponseModel>? Models { get; set; }
}public class GetAllProductsByFilterResponseModel
{
//
public long Id { get; set; }
//
public string Title { get; set; }
//
public string Description { get; set; }
//
public string ShortInfomation { get; set; }
//
public string FullInformation { get; set; }
//
public long Price { get; set; }
//
public int Discount { get; set; }
//
public int Rate { get; set; }
//
public string ImagePath { get; set; }
//
public string ThumbnailPath { get; set; }
//
public int SaleCount { get; set; }
//
public int ViewCount { get; set; }
//
public int RemainingCount { get; set; }
}
@@ -0,0 +1,7 @@
namespace CMSMicroservice.Application.ProductsCQ.Queries.GetProducts;
public record GetProductsQuery : IRequest<GetProductsResponseDto>
{
//
public long Id { get; init; }
}
@@ -0,0 +1,22 @@
namespace CMSMicroservice.Application.ProductsCQ.Queries.GetProducts;
public class GetProductsQueryHandler : IRequestHandler<GetProductsQuery, GetProductsResponseDto>
{
private readonly IApplicationDbContext _context;
public GetProductsQueryHandler(IApplicationDbContext context)
{
_context = context;
}
public async Task<GetProductsResponseDto> Handle(GetProductsQuery request,
CancellationToken cancellationToken)
{
var response = await _context.Productss
.AsNoTracking()
.Where(x => x.Id == request.Id)
.ProjectToType<GetProductsResponseDto>()
.FirstOrDefaultAsync(cancellationToken);
return response ?? throw new NotFoundException(nameof(Products), request.Id);
}
}
@@ -0,0 +1,16 @@
namespace CMSMicroservice.Application.ProductsCQ.Queries.GetProducts;
public class GetProductsQueryValidator : AbstractValidator<GetProductsQuery>
{
public GetProductsQueryValidator()
{
RuleFor(model => model.Id)
.NotNull();
}
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
{
var result = await ValidateAsync(ValidationContext<GetProductsQuery>.CreateWithOptions((GetProductsQuery)model, x => x.IncludeProperties(propertyName)));
if (result.IsValid)
return Array.Empty<string>();
return result.Errors.Select(e => e.ErrorMessage);
};
}
@@ -0,0 +1,31 @@
namespace CMSMicroservice.Application.ProductsCQ.Queries.GetProducts;
public class GetProductsResponseDto
{
//
public long Id { get; set; }
//
public string Title { get; set; }
//
public string Description { get; set; }
//
public string ShortInfomation { get; set; }
//
public string FullInformation { get; set; }
//
public long Price { get; set; }
//
public int Discount { get; set; }
//
public int Rate { get; set; }
//
public string ImagePath { get; set; }
//
public string ThumbnailPath { get; set; }
//
public int SaleCount { get; set; }
//
public int ViewCount { get; set; }
//
public int RemainingCount { get; set; }
}