update 2
This commit is contained in:
+7
@@ -0,0 +1,7 @@
|
||||
namespace BackOffice.BFF.Application.ProductsCQ.Queries.GetProductGallery;
|
||||
|
||||
public record GetProductGalleryQuery : IRequest<GetProductGalleryResponseDto>
|
||||
{
|
||||
public long ProductId { get; init; }
|
||||
}
|
||||
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
using BackOffice.BFF.Application.Common.Interfaces;
|
||||
using CMSMicroservice.Protobuf.Protos.ProductGallerys;
|
||||
using CMSMicroservice.Protobuf.Protos.ProductImages;
|
||||
|
||||
namespace BackOffice.BFF.Application.ProductsCQ.Queries.GetProductGallery;
|
||||
|
||||
public class GetProductGalleryQueryHandler : IRequestHandler<GetProductGalleryQuery, GetProductGalleryResponseDto>
|
||||
{
|
||||
private readonly IApplicationContractContext _context;
|
||||
|
||||
public GetProductGalleryQueryHandler(IApplicationContractContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<GetProductGalleryResponseDto> Handle(GetProductGalleryQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
var galleryRequest = new GetAllProductGallerysByFilterRequest
|
||||
{
|
||||
Filter = new GetAllProductGallerysByFilterFilter()
|
||||
};
|
||||
|
||||
var galleryResponse = await _context.ProductGallerys.GetAllProductGallerysByFilterAsync(galleryRequest, cancellationToken: cancellationToken);
|
||||
|
||||
// Filter by product id on client side because generated type may not support assigning Int64Value directly
|
||||
var filteredModels = galleryResponse?.Models?.Where(x => x.ProductId == request.ProductId).ToList();
|
||||
|
||||
var result = new GetProductGalleryResponseDto();
|
||||
|
||||
if (filteredModels == null || filteredModels.Count == 0)
|
||||
return result;
|
||||
|
||||
foreach (var item in filteredModels)
|
||||
{
|
||||
var image = await _context.ProductImages.GetProductImagesAsync(new GetProductImagesRequest
|
||||
{
|
||||
Id = item.ProductImageId
|
||||
}, cancellationToken: cancellationToken);
|
||||
|
||||
if (image == null)
|
||||
continue;
|
||||
|
||||
result.Items.Add(new ProductGalleryItemDto
|
||||
{
|
||||
ProductGalleryId = item.Id,
|
||||
ProductImageId = item.ProductImageId,
|
||||
Title = image.Title,
|
||||
ImagePath = image.ImagePath,
|
||||
ImageThumbnailPath = image.ImageThumbnailPath
|
||||
});
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
namespace BackOffice.BFF.Application.ProductsCQ.Queries.GetProductGallery;
|
||||
|
||||
public class GetProductGalleryResponseDto
|
||||
{
|
||||
public List<ProductGalleryItemDto> Items { get; set; } = new();
|
||||
}
|
||||
|
||||
public class ProductGalleryItemDto
|
||||
{
|
||||
public long ProductGalleryId { get; set; }
|
||||
public long ProductImageId { get; set; }
|
||||
public string Title { get; set; }
|
||||
public string ImagePath { get; set; }
|
||||
public string ImageThumbnailPath { get; set; }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user