using CMSMicroservice.Application.Common.Interfaces; using CMSMicroservice.Domain.Entities; using Mapster; namespace CMSMicroservice.Application.PackageCQ.Queries.GetCustomerPackages; public class GetCustomerPackagesQueryHandler : IRequestHandler> { private readonly IApplicationDbContext _context; public GetCustomerPackagesQueryHandler(IApplicationDbContext context) { _context = context; } public async Task> Handle(GetCustomerPackagesQuery request, CancellationToken cancellationToken) { var query = _context.Packages .AsNoTracking() .AsQueryable(); // Filter by PackageType if specified if (request.PackageTypeFilter.HasValue) { // Note: Package entity doesn't have PackageType enum, so we filter by convention // Assuming Title or Description contains the package type indicator // If Package entity needs PackageType field, it should be added to migration } // Get all packages (assuming all are available unless marked otherwise) var packages = await query .ProjectToType() .ToListAsync(cancellationToken); // Map additional fields foreach (var package in packages) { package.Name = package.Title; package.ImageUrl = package.ImagePath; package.Currency = "IRR"; package.IsAvailable = true; package.ValidityDays = 365; // Default validity package.IsPopular = false; package.ShortDescription = package.Description?.Length > 100 ? package.Description.Substring(0, 100) + "..." : package.Description; } return packages; } }