diff --git a/src/FrontOffice.BFF.Application/ProductsCQ/Queries/GetAllProductsByFilter/GetAllProductsByFilterQuery.cs b/src/FrontOffice.BFF.Application/ProductsCQ/Queries/GetAllProductsByFilter/GetAllProductsByFilterQuery.cs index 6af47b0..c6cc5cb 100644 --- a/src/FrontOffice.BFF.Application/ProductsCQ/Queries/GetAllProductsByFilter/GetAllProductsByFilterQuery.cs +++ b/src/FrontOffice.BFF.Application/ProductsCQ/Queries/GetAllProductsByFilter/GetAllProductsByFilterQuery.cs @@ -1,21 +1,29 @@ namespace FrontOffice.BFF.Application.ProductsCQ.Queries.GetAllProductsByFilter; public record GetAllProductsByFilterQuery : IRequest { - // - public long? Id { get; init; } - // - public string? Title { get; init; } - // - public string? Description { get; init; } - // - public string? ShortInfomation { get; init; } - // - public string? FullInformation { get; init; } - // - public long? Price { get; init; } - // - public int? Discount { get; init; } - // - public int? Rate { get; init; } + //موقعیت صفحه بندی + public PaginationState? PaginationState { get; init; } + //مرتب سازی بر اساس + public string? SortBy { get; init; } + //فیلتر + public GetAllProductsByFilterFilter? Filter { get; init; } -} \ No newline at end of file +}public class GetAllProductsByFilterFilter +{ + // + public long? Id { get; set; } + // + public string? Title { get; set; } + // + public string? Description { get; set; } + // + public string? ShortInfomation { get; set; } + // + public string? FullInformation { get; set; } + // + public long? Price { get; set; } + // + public int? Discount { get; set; } + // + public int? Rate { get; set; } +} diff --git a/src/FrontOffice.BFF.Application/ProductsCQ/Queries/GetAllProductsByFilter/GetAllProductsByFilterResponseDto.cs b/src/FrontOffice.BFF.Application/ProductsCQ/Queries/GetAllProductsByFilter/GetAllProductsByFilterResponseDto.cs index 045080e..bf61c01 100644 --- a/src/FrontOffice.BFF.Application/ProductsCQ/Queries/GetAllProductsByFilter/GetAllProductsByFilterResponseDto.cs +++ b/src/FrontOffice.BFF.Application/ProductsCQ/Queries/GetAllProductsByFilter/GetAllProductsByFilterResponseDto.cs @@ -1,5 +1,12 @@ namespace FrontOffice.BFF.Application.ProductsCQ.Queries.GetAllProductsByFilter; public class GetAllProductsByFilterResponseDto +{ + //متادیتا + public MetaData MetaData { get; set; } + //مدل خروجی + public List? Models { get; set; } + +}public class GetAllProductsByFilterResponseModel { // public long Id { get; set; } @@ -27,5 +34,4 @@ public class GetAllProductsByFilterResponseDto public int ViewCount { get; set; } // public int RemainingCount { get; set; } - -} \ No newline at end of file +} diff --git a/src/FrontOffice.BFF.WebApi/Services/ProductsService.cs b/src/FrontOffice.BFF.WebApi/Services/ProductsService.cs index 1e592a1..210f34d 100644 --- a/src/FrontOffice.BFF.WebApi/Services/ProductsService.cs +++ b/src/FrontOffice.BFF.WebApi/Services/ProductsService.cs @@ -15,8 +15,8 @@ public class ProductsService : ProductsContract.ProductsContractBase { return await _dispatchRequestToCQRS.Handle(request, context); } - public override async Task GetAllProductsByFilter(GetAllProductsByFilterFilter request, ServerCallContext context) + public override async Task GetAllProductsByFilter(GetAllProductsByFilterRequest request, ServerCallContext context) { - return await _dispatchRequestToCQRS.Handle(request, context); + return await _dispatchRequestToCQRS.Handle(request, context); } } diff --git a/src/Protobufs/FrontOffice.BFF.Products.Protobuf/Protos/products.proto b/src/Protobufs/FrontOffice.BFF.Products.Protobuf/Protos/products.proto index 5c3f335..e2263c9 100644 --- a/src/Protobufs/FrontOffice.BFF.Products.Protobuf/Protos/products.proto +++ b/src/Protobufs/FrontOffice.BFF.Products.Protobuf/Protos/products.proto @@ -18,7 +18,7 @@ service ProductsContract }; }; - rpc GetAllProductsByFilter(GetAllProductsByFilterFilter) returns (GetAllProductsByFilterResponseModel){ + rpc GetAllProductsByFilter(GetAllProductsByFilterRequest) returns (GetAllProductsByFilterResponse){ option (google.api.http) = { get: "/GetAllProductsByFilter" @@ -45,6 +45,12 @@ message GetProductsResponse int32 view_count = 12; int32 remaining_count = 13; } +message GetAllProductsByFilterRequest +{ + PaginationState pagination_state = 1; + google.protobuf.StringValue sort_by = 2; + GetAllProductsByFilterFilter filter = 3; +} message GetAllProductsByFilterFilter { google.protobuf.Int64Value id = 1; @@ -56,6 +62,11 @@ message GetAllProductsByFilterFilter google.protobuf.Int32Value discount = 7; google.protobuf.Int32Value rate = 8; } +message GetAllProductsByFilterResponse +{ + MetaData meta_data = 1; + repeated GetAllProductsByFilterResponseModel models = 2; +} message GetAllProductsByFilterResponseModel { int64 id = 1; diff --git a/src/Protobufs/FrontOffice.BFF.Products.Protobuf/Validator/GetAllProductsByFilterRequestValidator.cs b/src/Protobufs/FrontOffice.BFF.Products.Protobuf/Validator/GetAllProductsByFilterRequestValidator.cs new file mode 100644 index 0000000..aebbce5 --- /dev/null +++ b/src/Protobufs/FrontOffice.BFF.Products.Protobuf/Validator/GetAllProductsByFilterRequestValidator.cs @@ -0,0 +1,17 @@ +using FluentValidation; +using FrontOfficeMicroservice.Protobuf.Protos.Products; +namespace FrontOfficeMicroservice.Protobuf.Validator.Products; + +public class GetAllProductsByFilterRequestValidator : AbstractValidator +{ + public GetAllProductsByFilterRequestValidator() + { + } + public Func>> ValidateValue => async (model, propertyName) => + { + var result = await ValidateAsync(ValidationContext.CreateWithOptions((GetAllProductsByFilterRequest)model, x => x.IncludeProperties(propertyName))); + if (result.IsValid) + return Array.Empty(); + return result.Errors.Select(e => e.ErrorMessage); + }; +}