Skip to content

Commit

Permalink
fix: endDate, startDate, singleBeds, doubleBeds query param
Browse files Browse the repository at this point in the history
  • Loading branch information
fernirteam committed May 12, 2024
1 parent 1adef39 commit cde32db
Showing 1 changed file with 5 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,15 @@ public IEnumerable<Advert> Search(
(query == null || a.Name.ToUpper().Contains(query.ToUpper())) &&
(category == null || a.CategoryId == category) &&
(startDate == null || endDate == null || a.Reservations.Any(r => r.StartDate <= endDate && r.EndDate >= startDate)) &&
(startDate == null || endDate == null || !a.Reservations.Any(r => r.StartDate <= endDate && r.EndDate >= startDate)) &&
(minCost == null || minCost <= a.PricePerNight) &&
(maxCost == null || a.PricePerNight <= maxCost) &&
(singleBeds == null || CheckNumberOfSignleBeds(a, (int)singleBeds)) &&
(doubleBeds == null || CheckNumberOfDoubleBeds(a, (int)doubleBeds)) &&
(singleBeds == null || singleBeds >= 8 || a.NumberOfSingleBeds == singleBeds) &&
(singleBeds == null || singleBeds < 8 || a.NumberOfSingleBeds >= singleBeds) &&
(doubleBeds == null || doubleBeds >= 8 || a.NumberOfSingleBeds == doubleBeds) &&
(doubleBeds == null || doubleBeds < 8 || a.NumberOfSingleBeds >= doubleBeds) &&
(wifi == null || a.Wifi) &&
(petsAllowed == null || a.PetsAllowed) &&
Expand All @@ -80,28 +82,4 @@ public IEnumerable<Advert> Search(
(heating == null || a.Heating)
);
}

private bool CheckNumberOfSignleBeds(Advert advert, int numberOfSignleBeds)
{
if (numberOfSignleBeds < 8)
{
return advert.NumberOfSingleBeds == numberOfSignleBeds;
}
else
{
return advert.NumberOfSingleBeds >= numberOfSignleBeds;
}
}

private bool CheckNumberOfDoubleBeds(Advert advert, int numberOfDoubleBeds)
{
if (numberOfDoubleBeds < 8)
{
return advert.NumberOfDoubleBeds == numberOfDoubleBeds;
}
else
{
return advert.NumberOfDoubleBeds >= numberOfDoubleBeds;
}
}
}

0 comments on commit cde32db

Please sign in to comment.