fix: exclude past dates in price tables

This commit is contained in:
Björn Fromme
2026-08-06 12:19:30 +02:00
parent 577f7445ab
commit b82e017f73
3 changed files with 42 additions and 13 deletions
+10 -2
View File
@@ -15,6 +15,7 @@ use App\Repository\Groups\AccommodationPriceRepository;
use App\Repository\Groups\AccommodationRepository;
use App\Service\AccommodationPriceCoverage;
use App\Service\PriceTimelineBuilder;
use Carbon\CarbonImmutable;
use Psr\Cache\InvalidArgumentException;
use Psr\Log\LoggerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
@@ -57,11 +58,18 @@ class ContingentController extends AbstractController
$yearStart = new \DateTimeImmutable("{$query->year}-01-01");
$yearEnd = new \DateTimeImmutable("{$query->year}-12-31");
$prices = $this->priceRepository->findByHotelCodeAndDateRange($query->hotelCode, $yearStart, $yearEnd);
// Past date ranges are of no use to API consumers: never start the timeline before today.
$rangeStart = max($yearStart, CarbonImmutable::now()->setTime(0, 0));
if ($rangeStart > $yearEnd) {
return $this->json([]);
}
$prices = $this->priceRepository->findByHotelCodeAndDateRange($query->hotelCode, $rangeStart, $yearEnd);
$currency = $accommodation->getCurrency();
return $this->json($this->priceTimelineBuilder->buildTimeline($prices, $yearStart, $yearEnd, $currency));
return $this->json($this->priceTimelineBuilder->buildTimeline($prices, $rangeStart, $yearEnd, $currency));
}
#[Route(path: '/contingents/calendar', name: 'api_contingents_calendar', methods: ['GET'])]