Add category products query and update endpoints
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
namespace BackOffice.BFF.WebApi.Common.Mappings;
|
||||
|
||||
using BackOffice.BFF.Application.ProductsCQ.Queries.GetCategories;
|
||||
using BackOffice.BFF.Application.ProductsCQ.Queries.GetProductsForCategory;
|
||||
using BackOffice.BFF.Application.ProductsCQ.Queries.GetProductGallery;
|
||||
using BackOffice.BFF.Products.Protobuf.Protos.Products;
|
||||
|
||||
public class ProductsProfile : IRegister
|
||||
@@ -22,6 +24,39 @@ public class ProductsProfile : IRegister
|
||||
})
|
||||
}
|
||||
});
|
||||
|
||||
// Map GetProductsForCategory response DTO to protobuf response
|
||||
config.NewConfig<GetProductsForCategoryResponseDto, GetProductsForCategoryResponse>()
|
||||
.MapWith(src => new GetProductsForCategoryResponse
|
||||
{
|
||||
Items =
|
||||
{
|
||||
(src.Items ?? Enumerable.Empty<CategoryProductItemDto>())
|
||||
.Select(x => new CategoryProductItem
|
||||
{
|
||||
Id = x.Id,
|
||||
Title = x.Title ?? string.Empty,
|
||||
Selected = x.Selected
|
||||
})
|
||||
}
|
||||
});
|
||||
|
||||
// Map GetProductGallery response DTO to protobuf response
|
||||
config.NewConfig<GetProductGalleryResponseDto, GetProductGalleryResponse>()
|
||||
.MapWith(src => new GetProductGalleryResponse
|
||||
{
|
||||
Items =
|
||||
{
|
||||
(src.Items ?? Enumerable.Empty<ProductGalleryItemDto>())
|
||||
.Select(x => new ProductGalleryItem
|
||||
{
|
||||
ProductGalleryId = x.ProductGalleryId,
|
||||
ProductImageId = x.ProductImageId,
|
||||
Title = x.Title ?? string.Empty,
|
||||
ImagePath = x.ImagePath ?? string.Empty,
|
||||
ImageThumbnailPath = x.ImageThumbnailPath ?? string.Empty
|
||||
})
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,8 @@ using BackOffice.BFF.Application.ProductsCQ.Queries.GetProductGallery;
|
||||
using BackOffice.BFF.Application.ProductsCQ.Commands.RemoveProductImage;
|
||||
using BackOffice.BFF.Application.ProductsCQ.Queries.GetCategories;
|
||||
using BackOffice.BFF.Application.ProductsCQ.Commands.UpdateProductCategories;
|
||||
using BackOffice.BFF.Application.ProductsCQ.Queries.GetProductsForCategory;
|
||||
using BackOffice.BFF.Application.ProductsCQ.Commands.UpdateCategoryProducts;
|
||||
|
||||
namespace BackOffice.BFF.WebApi.Services;
|
||||
|
||||
@@ -71,4 +73,14 @@ public class ProductsService : ProductsContract.ProductsContractBase
|
||||
{
|
||||
return await _dispatchRequestToCQRS.Handle<UpdateProductCategoriesRequest, UpdateProductCategoriesCommand>(request, context);
|
||||
}
|
||||
|
||||
public override async Task<GetProductsForCategoryResponse> GetProductsForCategory(GetProductsForCategoryRequest request, ServerCallContext context)
|
||||
{
|
||||
return await _dispatchRequestToCQRS.Handle<GetProductsForCategoryRequest, GetProductsForCategoryQuery, GetProductsForCategoryResponse>(request, context);
|
||||
}
|
||||
|
||||
public override async Task<Empty> UpdateCategoryProducts(UpdateCategoryProductsRequest request, ServerCallContext context)
|
||||
{
|
||||
return await _dispatchRequestToCQRS.Handle<UpdateCategoryProductsRequest, UpdateCategoryProductsCommand>(request, context);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user