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,9 @@
namespace CMSMicroservice.Application.ProductGallerysCQ.Commands.CreateNewProductGallerys;
public record CreateNewProductGallerysCommand : IRequest<CreateNewProductGallerysResponseDto>
{
//
public long ProductImageId { get; init; }
//
public long ProductId { get; init; }
}

View File

@@ -0,0 +1,21 @@
using CMSMicroservice.Domain.Events;
namespace CMSMicroservice.Application.ProductGallerysCQ.Commands.CreateNewProductGallerys;
public class CreateNewProductGallerysCommandHandler : IRequestHandler<CreateNewProductGallerysCommand, CreateNewProductGallerysResponseDto>
{
private readonly IApplicationDbContext _context;
public CreateNewProductGallerysCommandHandler(IApplicationDbContext context)
{
_context = context;
}
public async Task<CreateNewProductGallerysResponseDto> Handle(CreateNewProductGallerysCommand request,
CancellationToken cancellationToken)
{
var entity = request.Adapt<ProductGallerys>();
await _context.ProductGalleryss.AddAsync(entity, cancellationToken);
entity.AddDomainEvent(new CreateNewProductGallerysEvent(entity));
await _context.SaveChangesAsync(cancellationToken);
return entity.Adapt<CreateNewProductGallerysResponseDto>();
}
}

View File

@@ -0,0 +1,18 @@
namespace CMSMicroservice.Application.ProductGallerysCQ.Commands.CreateNewProductGallerys;
public class CreateNewProductGallerysCommandValidator : AbstractValidator<CreateNewProductGallerysCommand>
{
public CreateNewProductGallerysCommandValidator()
{
RuleFor(model => model.ProductImageId)
.NotNull();
RuleFor(model => model.ProductId)
.NotNull();
}
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
{
var result = await ValidateAsync(ValidationContext<CreateNewProductGallerysCommand>.CreateWithOptions((CreateNewProductGallerysCommand)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.ProductGallerysCQ.Commands.CreateNewProductGallerys;
public class CreateNewProductGallerysResponseDto
{
//
public long Id { get; set; }
}

View File

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

View File

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

View File

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

View File

@@ -0,0 +1,11 @@
namespace CMSMicroservice.Application.ProductGallerysCQ.Commands.UpdateProductGallerys;
public record UpdateProductGallerysCommand : IRequest<Unit>
{
//
public long Id { get; init; }
//
public long ProductImageId { get; init; }
//
public long ProductId { get; init; }
}

View File

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

View File

@@ -0,0 +1,20 @@
namespace CMSMicroservice.Application.ProductGallerysCQ.Commands.UpdateProductGallerys;
public class UpdateProductGallerysCommandValidator : AbstractValidator<UpdateProductGallerysCommand>
{
public UpdateProductGallerysCommandValidator()
{
RuleFor(model => model.Id)
.NotNull();
RuleFor(model => model.ProductImageId)
.NotNull();
RuleFor(model => model.ProductId)
.NotNull();
}
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
{
var result = await ValidateAsync(ValidationContext<UpdateProductGallerysCommand>.CreateWithOptions((UpdateProductGallerysCommand)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.ProductGallerysCQ.EventHandlers;
public class CreateNewProductGallerysEventHandler : INotificationHandler<CreateNewProductGallerysEvent>
{
private readonly ILogger<
CreateNewProductGallerysEventHandler> _logger;
public CreateNewProductGallerysEventHandler(ILogger<CreateNewProductGallerysEventHandler> logger)
{
_logger = logger;
}
public Task Handle(CreateNewProductGallerysEvent 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.ProductGallerysCQ.EventHandlers;
public class DeleteProductGallerysEventHandler : INotificationHandler<DeleteProductGallerysEvent>
{
private readonly ILogger<
DeleteProductGallerysEventHandler> _logger;
public DeleteProductGallerysEventHandler(ILogger<DeleteProductGallerysEventHandler> logger)
{
_logger = logger;
}
public Task Handle(DeleteProductGallerysEvent 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.ProductGallerysCQ.EventHandlers;
public class UpdateProductGallerysEventHandler : INotificationHandler<UpdateProductGallerysEvent>
{
private readonly ILogger<
UpdateProductGallerysEventHandler> _logger;
public UpdateProductGallerysEventHandler(ILogger<UpdateProductGallerysEventHandler> logger)
{
_logger = logger;
}
public Task Handle(UpdateProductGallerysEvent notification, CancellationToken cancellationToken)
{
_logger.LogInformation("Domain Event: {DomainEvent}", notification.GetType().Name);
return Task.CompletedTask;
}
}

View File

@@ -0,0 +1,19 @@
namespace CMSMicroservice.Application.ProductGallerysCQ.Queries.GetAllProductGallerysByFilter;
public record GetAllProductGallerysByFilterQuery : IRequest<GetAllProductGallerysByFilterResponseDto>
{
//موقعیت صفحه بندی
public PaginationState? PaginationState { get; init; }
//مرتب سازی بر اساس
public string? SortBy { get; init; }
//فیلتر
public GetAllProductGallerysByFilterFilter? Filter { get; init; }
}public class GetAllProductGallerysByFilterFilter
{
//
public long? Id { get; set; }
//
public long? ProductImageId { get; set; }
//
public long? ProductId { get; set; }
}

View File

@@ -0,0 +1,32 @@
namespace CMSMicroservice.Application.ProductGallerysCQ.Queries.GetAllProductGallerysByFilter;
public class GetAllProductGallerysByFilterQueryHandler : IRequestHandler<GetAllProductGallerysByFilterQuery, GetAllProductGallerysByFilterResponseDto>
{
private readonly IApplicationDbContext _context;
public GetAllProductGallerysByFilterQueryHandler(IApplicationDbContext context)
{
_context = context;
}
public async Task<GetAllProductGallerysByFilterResponseDto> Handle(GetAllProductGallerysByFilterQuery request, CancellationToken cancellationToken)
{
var query = _context.ProductGalleryss
.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.ProductImageId == null || x.ProductImageId == request.Filter.ProductImageId)
.Where(x => request.Filter.ProductId == null || x.ProductId == request.Filter.ProductId)
;
}
return new GetAllProductGallerysByFilterResponseDto
{
MetaData = await query.GetMetaData(request.PaginationState, cancellationToken),
Models = await query.PaginatedListAsync(paginationState: request.PaginationState)
.ProjectToType<GetAllProductGallerysByFilterResponseModel>().ToListAsync(cancellationToken)
};
}
}

View File

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

View File

@@ -0,0 +1,17 @@
namespace CMSMicroservice.Application.ProductGallerysCQ.Queries.GetAllProductGallerysByFilter;
public class GetAllProductGallerysByFilterResponseDto
{
//متادیتا
public MetaData MetaData { get; set; }
//مدل خروجی
public List<GetAllProductGallerysByFilterResponseModel>? Models { get; set; }
}public class GetAllProductGallerysByFilterResponseModel
{
//
public long Id { get; set; }
//
public long ProductImageId { get; set; }
//
public long ProductId { get; set; }
}

View File

@@ -0,0 +1,7 @@
namespace CMSMicroservice.Application.ProductGallerysCQ.Queries.GetProductGallerys;
public record GetProductGallerysQuery : IRequest<GetProductGallerysResponseDto>
{
//
public long Id { get; init; }
}

View File

@@ -0,0 +1,22 @@
namespace CMSMicroservice.Application.ProductGallerysCQ.Queries.GetProductGallerys;
public class GetProductGallerysQueryHandler : IRequestHandler<GetProductGallerysQuery, GetProductGallerysResponseDto>
{
private readonly IApplicationDbContext _context;
public GetProductGallerysQueryHandler(IApplicationDbContext context)
{
_context = context;
}
public async Task<GetProductGallerysResponseDto> Handle(GetProductGallerysQuery request,
CancellationToken cancellationToken)
{
var response = await _context.ProductGalleryss
.AsNoTracking()
.Where(x => x.Id == request.Id)
.ProjectToType<GetProductGallerysResponseDto>()
.FirstOrDefaultAsync(cancellationToken);
return response ?? throw new NotFoundException(nameof(ProductGallerys), request.Id);
}
}

View File

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

View File

@@ -0,0 +1,11 @@
namespace CMSMicroservice.Application.ProductGallerysCQ.Queries.GetProductGallerys;
public class GetProductGallerysResponseDto
{
//
public long Id { get; set; }
//
public long ProductImageId { get; set; }
//
public long ProductId { get; set; }
}