refactor: rename response properties in PackageService for consistency
This commit is contained in:
-69
@@ -1,69 +0,0 @@
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using CMSMicroservice.Application.Common.Interfaces;
|
||||
using Mapster;
|
||||
using MediatR;
|
||||
|
||||
namespace CMSMicroservice.Application.ProductsCQ.Queries.GetAllProductsByFilter;
|
||||
|
||||
public class
|
||||
GetAllProductsByFilterQueryHandler : IRequestHandler<GetAllProductsByFilterQuery, GetAllProductsByFilterResponseDto>
|
||||
{
|
||||
private readonly IApplicationDbContext _context;
|
||||
|
||||
public GetAllProductsByFilterQueryHandler(IApplicationDbContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<GetAllProductsByFilterResponseDto> Handle(GetAllProductsByFilterQuery request,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
var grpcRequest = new CmsProductsProtos.GetAllProductsByFilterRequest
|
||||
{
|
||||
PaginationState = request.PaginationState is { } pagination
|
||||
? new CmsPaginationState
|
||||
{
|
||||
PageNumber = pagination.PageNumber,
|
||||
PageSize = pagination.PageSize
|
||||
}
|
||||
: null,
|
||||
SortBy = request.SortBy,
|
||||
Filter = BuildFilter(request.Filter)
|
||||
};
|
||||
|
||||
var result = await _context.Product.GetAllProductsByFilterAsync(grpcRequest,
|
||||
cancellationToken: cancellationToken);
|
||||
|
||||
if (request.Filter?.CategoryId is { } categoryId)
|
||||
{
|
||||
var matchingModels = result.Models
|
||||
.Where(model => model.CategoryIds.Contains(categoryId))
|
||||
.ToList();
|
||||
result.Models.Clear();
|
||||
result.Models.AddRange(matchingModels);
|
||||
}
|
||||
return result.Adapt<GetAllProductsByFilterResponseDto>();
|
||||
}
|
||||
|
||||
private static CmsProductsProtos.GetAllProductsByFilterFilter? BuildFilter(GetAllProductsByFilterFilter? filter)
|
||||
{
|
||||
if (filter is null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return new CmsProductsProtos.GetAllProductsByFilterFilter
|
||||
{
|
||||
Id = filter.Id,
|
||||
Title = filter.Title,
|
||||
Description = filter.Description,
|
||||
ShortInfomation = filter.ShortInfomation,
|
||||
FullInformation = filter.FullInformation,
|
||||
Price = filter.Price,
|
||||
Discount = filter.Discount,
|
||||
Rate = filter.Rate
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -129,7 +129,7 @@ public class PackageService : PackageContract.PackageContractBase
|
||||
|
||||
return new GetCustomerPackagesResponse
|
||||
{
|
||||
Packages = { packages }
|
||||
Models = { packages }
|
||||
};
|
||||
}
|
||||
|
||||
@@ -162,23 +162,12 @@ public class PackageService : PackageContract.PackageContractBase
|
||||
};
|
||||
|
||||
return new GetCustomerPackageDetailsResponse
|
||||
{
|
||||
Package = new CustomerPackageModel
|
||||
{
|
||||
Id = request.PackageId,
|
||||
Name = "پکیج طلایی",
|
||||
Title = "پکیج طلایی", // Populate alias field
|
||||
Title = "پکیج طلایی",
|
||||
Description = "پکیج کامل با تمام امکانات برای کاربران حرفهای",
|
||||
Price = 5600000,
|
||||
Currency = "IRR",
|
||||
PackageType = PackageTypeEnum.PackageTypeGolden,
|
||||
IsAvailable = true,
|
||||
ImageUrl = "/images/packages/golden-detail.jpg",
|
||||
ImagePath = "/images/packages/golden-detail.jpg", // Populate alias field
|
||||
ValidityDays = 365,
|
||||
IsPopular = true,
|
||||
ShortDescription = "بهترین انتخاب برای کسب درآمد حداکثری"
|
||||
},
|
||||
ImagePath = "/images/packages/golden-detail.jpg",
|
||||
Features = { packageFeatures },
|
||||
Requirements = new PurchaseRequirements
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user