Generator Changes at 11/12/2025 1:32:03 AM +03:30
This commit is contained in:
@@ -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; }
|
||||
}
|
||||
@@ -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)
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
};
|
||||
}
|
||||
@@ -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; }
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace CMSMicroservice.Application.ProductImagesCQ.Queries.GetProductImages;
|
||||
public record GetProductImagesQuery : IRequest<GetProductImagesResponseDto>
|
||||
{
|
||||
//
|
||||
public long Id { get; init; }
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
};
|
||||
}
|
||||
@@ -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; }
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user