feat: derive calendar date range from price configurations
This commit is contained in:
@@ -72,9 +72,6 @@ class ContingentController extends AbstractController
|
||||
#[MapQueryString(validationFailedStatusCode: Response::HTTP_BAD_REQUEST)]
|
||||
ContingentCalendarQuery $query,
|
||||
): JsonResponse {
|
||||
$dateFrom = $query->dateFromDate();
|
||||
$dateTo = $query->dateToDate();
|
||||
|
||||
$accommodation = $this->accommodationRepository->findOneBy(['calendarCode' => $query->hotelCode]);
|
||||
|
||||
if (null === $accommodation) {
|
||||
@@ -83,6 +80,30 @@ class ContingentController extends AbstractController
|
||||
return $this->json(['error' => 'Hotel not found for hotelCode.'], Response::HTTP_BAD_REQUEST);
|
||||
}
|
||||
|
||||
$dateFrom = $query->dateFromDate();
|
||||
$dateTo = $query->dateToDate();
|
||||
|
||||
// Without an explicit range the persisted prices define one: what we have priced is what we sell.
|
||||
if (null === $dateFrom || null === $dateTo) {
|
||||
$bounds = $this->priceRepository->findPricedDateBoundsByHotelCode($query->hotelCode);
|
||||
|
||||
// Nothing priced means nothing sold, so there is no calendar to serve. This returns before
|
||||
// the snapshot is consulted, and deliberately so: the 502 below exists to avoid passing
|
||||
// unknown availability off as "all blocked", and here there is nothing to be unsure about.
|
||||
if (null === $bounds) {
|
||||
return $this->json([]);
|
||||
}
|
||||
|
||||
// Past date ranges are of no use to API consumers: never start the range before today.
|
||||
$dateFrom = max($bounds['from'], CarbonImmutable::now()->setTime(0, 0));
|
||||
$dateTo = $bounds['to'];
|
||||
|
||||
// Every priced period has already ended.
|
||||
if ($dateFrom > $dateTo) {
|
||||
return $this->json([]);
|
||||
}
|
||||
}
|
||||
|
||||
// An empty or stale snapshot must not be served as though every day were blocked: that
|
||||
// is a plausible-looking 200 nobody can distinguish from real data. Fail the way this
|
||||
// endpoint always failed instead, so existing consumers need no change.
|
||||
|
||||
Reference in New Issue
Block a user