Skip to content

Commit 0ebd0b8

Browse files
DangDang
authored andcommitted
Make spec filtering more robust with case-insensitive matching
- Updated SearchLevel2ModelsQueryHandler to handle multiple spec name formats: - Seats: 'Seats' or 'seats' (case-insensitive) - Fuel Type: 'Fuel Type', 'fuelType', or 'fuel_type' (case-insensitive) - Updated SearchVehiclesQueryHandler with same robust matching - Now handles different possible database formats for spec names - Build successful with no compilation errors
1 parent 4353312 commit 0ebd0b8

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

VehicleShowroomManagement/src/Application/Features/VehicleModels/Queries/SearchLevel2Models/SearchLevel2ModelsQueryHandler.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,16 @@ public async Task<SearchLevel2ModelsResult> Handle(SearchLevel2ModelsQuery reque
1515
foreach (var m in models)
1616
{
1717
var specs = await specRepository.FindAsync(s => s.ModelId == m.ModelNumber, cancellationToken);
18-
var seatsOk = !request.Seats.HasValue || specs.Any(s => s.SpecName == "Seats" && int.TryParse(s.SpecValue, out var v) && v == request.Seats.Value);
19-
var fuelOk = string.IsNullOrWhiteSpace(request.FuelType) || specs.Any(s => s.SpecName == "Fuel Type" && string.Equals(s.SpecValue, request.FuelType, StringComparison.OrdinalIgnoreCase));
18+
var vehicleSpecs = specs as VehicleSpec[] ?? specs.ToArray();
19+
var seatsOk = !request.Seats.HasValue || vehicleSpecs.Any(s =>
20+
(s.SpecName.Equals("Seats", StringComparison.OrdinalIgnoreCase) ||
21+
s.SpecName.Equals("seats", StringComparison.OrdinalIgnoreCase)) &&
22+
int.TryParse(s.SpecValue, out var v) && v == request.Seats.Value);
23+
var fuelOk = string.IsNullOrWhiteSpace(request.FuelType) || vehicleSpecs.Any(s =>
24+
(s.SpecName.Equals("Fuel Type", StringComparison.OrdinalIgnoreCase) ||
25+
s.SpecName.Equals("fuelType", StringComparison.OrdinalIgnoreCase) ||
26+
s.SpecName.Equals("fuel_type", StringComparison.OrdinalIgnoreCase)) &&
27+
string.Equals(s.SpecValue, request.FuelType, StringComparison.OrdinalIgnoreCase));
2028
if (seatsOk && fuelOk) filtered.Add(m);
2129
}
2230
models = filtered;

VehicleShowroomManagement/src/Application/Features/Vehicles/Queries/SearchVehicles/SearchVehiclesQueryHandler.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,15 @@ public async Task<SearchVehiclesResult> Handle(SearchVehiclesQuery request, Canc
1717
{
1818
var allSpecs = await specRepository.GetAllAsync(cancellationToken);
1919
var specs = allSpecs.Where(s =>
20-
(request.Seats == null || (s.SpecName == "Seats" && int.TryParse(s.SpecValue, out var val) && val == request.Seats)) ||
21-
(!string.IsNullOrWhiteSpace(request.FuelType) && s.SpecName == "Fuel Type" && s.SpecValue.Equals(request.FuelType, StringComparison.OrdinalIgnoreCase))
20+
(request.Seats == null ||
21+
((s.SpecName.Equals("Seats", StringComparison.OrdinalIgnoreCase) ||
22+
s.SpecName.Equals("seats", StringComparison.OrdinalIgnoreCase)) &&
23+
int.TryParse(s.SpecValue, out var val) && val == request.Seats)) ||
24+
(!string.IsNullOrWhiteSpace(request.FuelType) &&
25+
((s.SpecName.Equals("Fuel Type", StringComparison.OrdinalIgnoreCase) ||
26+
s.SpecName.Equals("fuelType", StringComparison.OrdinalIgnoreCase) ||
27+
s.SpecName.Equals("fuel_type", StringComparison.OrdinalIgnoreCase)) &&
28+
s.SpecValue.Equals(request.FuelType, StringComparison.OrdinalIgnoreCase)))
2229
);
2330
var modelIds = specs.Select(s => s.ModelId).ToHashSet();
2431
if (modelIds.Count > 0)
Binary file not shown.

0 commit comments

Comments
 (0)