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

View File

@@ -0,0 +1,11 @@
namespace CMSMicroservice.Application.ProductImagesCQ.Commands.CreateNewProductImages;
public record CreateNewProductImagesCommand : IRequest<CreateNewProductImagesResponseDto>
{
//
public string Title { get; init; }
//
public string ImagePath { get; init; }
//
public string ImageThumbnailPath { get; init; }
}

View File

@@ -0,0 +1,21 @@
using CMSMicroservice.Domain.Events;
namespace CMSMicroservice.Application.ProductImagesCQ.Commands.CreateNewProductImages;
public class CreateNewProductImagesCommandHandler : IRequestHandler<CreateNewProductImagesCommand, CreateNewProductImagesResponseDto>
{
private readonly IApplicationDbContext _context;
public CreateNewProductImagesCommandHandler(IApplicationDbContext context)
{
_context = context;
}
public async Task<CreateNewProductImagesResponseDto> Handle(CreateNewProductImagesCommand request,
CancellationToken cancellationToken)
{
var entity = request.Adapt<ProductImages>();
await _context.ProductImagess.AddAsync(entity, cancellationToken);
entity.AddDomainEvent(new CreateNewProductImagesEvent(entity));
await _context.SaveChangesAsync(cancellationToken);
return entity.Adapt<CreateNewProductImagesResponseDto>();
}
}

View File

@@ -0,0 +1,20 @@
namespace CMSMicroservice.Application.ProductImagesCQ.Commands.CreateNewProductImages;
public class CreateNewProductImagesCommandValidator : AbstractValidator<CreateNewProductImagesCommand>
{
public CreateNewProductImagesCommandValidator()
{
RuleFor(model => model.Title)
.NotEmpty();
RuleFor(model => model.ImagePath)
.NotEmpty();
RuleFor(model => model.ImageThumbnailPath)
.NotEmpty();
}
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
{
var result = await ValidateAsync(ValidationContext<CreateNewProductImagesCommand>.CreateWithOptions((CreateNewProductImagesCommand)model, x => x.IncludeProperties(propertyName)));
if (result.IsValid)
return Array.Empty<string>();
return result.Errors.Select(e => e.ErrorMessage);
};
}

View File

@@ -0,0 +1,7 @@
namespace CMSMicroservice.Application.ProductImagesCQ.Commands.CreateNewProductImages;
public class CreateNewProductImagesResponseDto
{
//
public long Id { get; set; }
}

View File

@@ -0,0 +1,7 @@
namespace CMSMicroservice.Application.ProductImagesCQ.Commands.DeleteProductImages;
public record DeleteProductImagesCommand : IRequest<Unit>
{
//
public long Id { get; init; }
}

View File

@@ -0,0 +1,22 @@
using CMSMicroservice.Domain.Events;
namespace CMSMicroservice.Application.ProductImagesCQ.Commands.DeleteProductImages;
public class DeleteProductImagesCommandHandler : IRequestHandler<DeleteProductImagesCommand, Unit>
{
private readonly IApplicationDbContext _context;
public DeleteProductImagesCommandHandler(IApplicationDbContext context)
{
_context = context;
}
public async Task<Unit> Handle(DeleteProductImagesCommand request, CancellationToken cancellationToken)
{
var entity = await _context.ProductImagess
.FirstOrDefaultAsync(x => x.Id == request.Id, cancellationToken) ?? throw new NotFoundException(nameof(ProductImages), request.Id);
entity.IsDeleted = true;
_context.ProductImagess.Update(entity);
entity.AddDomainEvent(new DeleteProductImagesEvent(entity));
await _context.SaveChangesAsync(cancellationToken);
return Unit.Value;
}
}

View File

@@ -0,0 +1,16 @@
namespace CMSMicroservice.Application.ProductImagesCQ.Commands.DeleteProductImages;
public class DeleteProductImagesCommandValidator : AbstractValidator<DeleteProductImagesCommand>
{
public DeleteProductImagesCommandValidator()
{
RuleFor(model => model.Id)
.NotNull();
}
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
{
var result = await ValidateAsync(ValidationContext<DeleteProductImagesCommand>.CreateWithOptions((DeleteProductImagesCommand)model, x => x.IncludeProperties(propertyName)));
if (result.IsValid)
return Array.Empty<string>();
return result.Errors.Select(e => e.ErrorMessage);
};
}

View File

@@ -0,0 +1,13 @@
namespace CMSMicroservice.Application.ProductImagesCQ.Commands.UpdateProductImages;
public record UpdateProductImagesCommand : IRequest<Unit>
{
//
public long Id { get; init; }
//
public string Title { get; init; }
//
public string ImagePath { get; init; }
//
public string ImageThumbnailPath { get; init; }
}

View File

@@ -0,0 +1,22 @@
using CMSMicroservice.Domain.Events;
namespace CMSMicroservice.Application.ProductImagesCQ.Commands.UpdateProductImages;
public class UpdateProductImagesCommandHandler : IRequestHandler<UpdateProductImagesCommand, Unit>
{
private readonly IApplicationDbContext _context;
public UpdateProductImagesCommandHandler(IApplicationDbContext context)
{
_context = context;
}
public async Task<Unit> Handle(UpdateProductImagesCommand request, CancellationToken cancellationToken)
{
var entity = await _context.ProductImagess
.FirstOrDefaultAsync(x => x.Id == request.Id, cancellationToken) ?? throw new NotFoundException(nameof(ProductImages), request.Id);
request.Adapt(entity);
_context.ProductImagess.Update(entity);
entity.AddDomainEvent(new UpdateProductImagesEvent(entity));
await _context.SaveChangesAsync(cancellationToken);
return Unit.Value;
}
}

View File

@@ -0,0 +1,22 @@
namespace CMSMicroservice.Application.ProductImagesCQ.Commands.UpdateProductImages;
public class UpdateProductImagesCommandValidator : AbstractValidator<UpdateProductImagesCommand>
{
public UpdateProductImagesCommandValidator()
{
RuleFor(model => model.Id)
.NotNull();
RuleFor(model => model.Title)
.NotEmpty();
RuleFor(model => model.ImagePath)
.NotEmpty();
RuleFor(model => model.ImageThumbnailPath)
.NotEmpty();
}
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
{
var result = await ValidateAsync(ValidationContext<UpdateProductImagesCommand>.CreateWithOptions((UpdateProductImagesCommand)model, x => x.IncludeProperties(propertyName)));
if (result.IsValid)
return Array.Empty<string>();
return result.Errors.Select(e => e.ErrorMessage);
};
}

View File

@@ -0,0 +1,22 @@
using CMSMicroservice.Domain.Events;
using Microsoft.Extensions.Logging;
namespace CMSMicroservice.Application.ProductImagesCQ.EventHandlers;
public class CreateNewProductImagesEventHandler : INotificationHandler<CreateNewProductImagesEvent>
{
private readonly ILogger<
CreateNewProductImagesEventHandler> _logger;
public CreateNewProductImagesEventHandler(ILogger<CreateNewProductImagesEventHandler> logger)
{
_logger = logger;
}
public Task Handle(CreateNewProductImagesEvent notification, CancellationToken cancellationToken)
{
_logger.LogInformation("Domain Event: {DomainEvent}", notification.GetType().Name);
return Task.CompletedTask;
}
}

View File

@@ -0,0 +1,22 @@
using CMSMicroservice.Domain.Events;
using Microsoft.Extensions.Logging;
namespace CMSMicroservice.Application.ProductImagesCQ.EventHandlers;
public class DeleteProductImagesEventHandler : INotificationHandler<DeleteProductImagesEvent>
{
private readonly ILogger<
DeleteProductImagesEventHandler> _logger;
public DeleteProductImagesEventHandler(ILogger<DeleteProductImagesEventHandler> logger)
{
_logger = logger;
}
public Task Handle(DeleteProductImagesEvent notification, CancellationToken cancellationToken)
{
_logger.LogInformation("Domain Event: {DomainEvent}", notification.GetType().Name);
return Task.CompletedTask;
}
}

View File

@@ -0,0 +1,22 @@
using CMSMicroservice.Domain.Events;
using Microsoft.Extensions.Logging;
namespace CMSMicroservice.Application.ProductImagesCQ.EventHandlers;
public class UpdateProductImagesEventHandler : INotificationHandler<UpdateProductImagesEvent>
{
private readonly ILogger<
UpdateProductImagesEventHandler> _logger;
public UpdateProductImagesEventHandler(ILogger<UpdateProductImagesEventHandler> logger)
{
_logger = logger;
}
public Task Handle(UpdateProductImagesEvent notification, CancellationToken cancellationToken)
{
_logger.LogInformation("Domain Event: {DomainEvent}", notification.GetType().Name);
return Task.CompletedTask;
}
}

View File

@@ -0,0 +1,21 @@
namespace CMSMicroservice.Application.ProductImagesCQ.Queries.GetAllProductImagesByFilter;
public record GetAllProductImagesByFilterQuery : IRequest<GetAllProductImagesByFilterResponseDto>
{
//موقعیت صفحه بندی
public PaginationState? PaginationState { get; init; }
//مرتب سازی بر اساس
public string? SortBy { get; init; }
//فیلتر
public GetAllProductImagesByFilterFilter? Filter { get; init; }
}public class GetAllProductImagesByFilterFilter
{
//
public long? Id { get; set; }
//
public string? Title { get; set; }
//
public string? ImagePath { get; set; }
//
public string? ImageThumbnailPath { get; set; }
}

View File

@@ -0,0 +1,33 @@
namespace CMSMicroservice.Application.ProductImagesCQ.Queries.GetAllProductImagesByFilter;
public class GetAllProductImagesByFilterQueryHandler : IRequestHandler<GetAllProductImagesByFilterQuery, GetAllProductImagesByFilterResponseDto>
{
private readonly IApplicationDbContext _context;
public GetAllProductImagesByFilterQueryHandler(IApplicationDbContext context)
{
_context = context;
}
public async Task<GetAllProductImagesByFilterResponseDto> Handle(GetAllProductImagesByFilterQuery request, CancellationToken cancellationToken)
{
var query = _context.ProductImagess
.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.ImagePath == null || x.ImagePath.Contains(request.Filter.ImagePath))
.Where(x => request.Filter.ImageThumbnailPath == null || x.ImageThumbnailPath.Contains(request.Filter.ImageThumbnailPath))
;
}
return new GetAllProductImagesByFilterResponseDto
{
MetaData = await query.GetMetaData(request.PaginationState, cancellationToken),
Models = await query.PaginatedListAsync(paginationState: request.PaginationState)
.ProjectToType<GetAllProductImagesByFilterResponseModel>().ToListAsync(cancellationToken)
};
}
}

View File

@@ -0,0 +1,14 @@
namespace CMSMicroservice.Application.ProductImagesCQ.Queries.GetAllProductImagesByFilter;
public class GetAllProductImagesByFilterQueryValidator : AbstractValidator<GetAllProductImagesByFilterQuery>
{
public GetAllProductImagesByFilterQueryValidator()
{
}
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
{
var result = await ValidateAsync(ValidationContext<GetAllProductImagesByFilterQuery>.CreateWithOptions((GetAllProductImagesByFilterQuery)model, x => x.IncludeProperties(propertyName)));
if (result.IsValid)
return Array.Empty<string>();
return result.Errors.Select(e => e.ErrorMessage);
};
}

View File

@@ -0,0 +1,19 @@
namespace CMSMicroservice.Application.ProductImagesCQ.Queries.GetAllProductImagesByFilter;
public class GetAllProductImagesByFilterResponseDto
{
//متادیتا
public MetaData MetaData { get; set; }
//مدل خروجی
public List<GetAllProductImagesByFilterResponseModel>? Models { get; set; }
}public class GetAllProductImagesByFilterResponseModel
{
//
public long Id { get; set; }
//
public string Title { get; set; }
//
public string ImagePath { get; set; }
//
public string ImageThumbnailPath { get; set; }
}

View File

@@ -0,0 +1,7 @@
namespace CMSMicroservice.Application.ProductImagesCQ.Queries.GetProductImages;
public record GetProductImagesQuery : IRequest<GetProductImagesResponseDto>
{
//
public long Id { get; init; }
}

View File

@@ -0,0 +1,22 @@
namespace CMSMicroservice.Application.ProductImagesCQ.Queries.GetProductImages;
public class GetProductImagesQueryHandler : IRequestHandler<GetProductImagesQuery, GetProductImagesResponseDto>
{
private readonly IApplicationDbContext _context;
public GetProductImagesQueryHandler(IApplicationDbContext context)
{
_context = context;
}
public async Task<GetProductImagesResponseDto> Handle(GetProductImagesQuery request,
CancellationToken cancellationToken)
{
var response = await _context.ProductImagess
.AsNoTracking()
.Where(x => x.Id == request.Id)
.ProjectToType<GetProductImagesResponseDto>()
.FirstOrDefaultAsync(cancellationToken);
return response ?? throw new NotFoundException(nameof(ProductImages), request.Id);
}
}

View File

@@ -0,0 +1,16 @@
namespace CMSMicroservice.Application.ProductImagesCQ.Queries.GetProductImages;
public class GetProductImagesQueryValidator : AbstractValidator<GetProductImagesQuery>
{
public GetProductImagesQueryValidator()
{
RuleFor(model => model.Id)
.NotNull();
}
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
{
var result = await ValidateAsync(ValidationContext<GetProductImagesQuery>.CreateWithOptions((GetProductImagesQuery)model, x => x.IncludeProperties(propertyName)));
if (result.IsValid)
return Array.Empty<string>();
return result.Errors.Select(e => e.ErrorMessage);
};
}

View File

@@ -0,0 +1,13 @@
namespace CMSMicroservice.Application.ProductImagesCQ.Queries.GetProductImages;
public class GetProductImagesResponseDto
{
//
public long Id { get; set; }
//
public string Title { get; set; }
//
public string ImagePath { get; set; }
//
public string ImageThumbnailPath { get; set; }
}