feat: derive calendar date range from price configurations

This commit is contained in:
Björn Fromme
2026-08-26 13:32:25 +02:00
parent 61e020c3d0
commit 80d734e7d6
6 changed files with 260 additions and 25 deletions
+44 -11
View File
@@ -17,21 +17,40 @@ final readonly class ContingentCalendarQuery
#[Assert\Regex(pattern: '/^[A-Za-z0-9_-]+$/')]
public string $hotelCode,
#[Assert\NotBlank]
#[Assert\Date]
public string $dateFrom,
public ?string $dateFrom = null,
#[Assert\NotBlank]
#[Assert\Date]
public string $dateTo,
public ?string $dateTo = null,
) {
}
#[Assert\Callback]
public function validateRange(ExecutionContextInterface $context): void
{
$dateFrom = self::parseDate($this->dateFrom);
$dateTo = self::parseDate($this->dateTo);
$from = $this->dateFrom;
$to = $this->dateTo;
$hasFrom = null !== $from && '' !== $from;
$hasTo = null !== $to && '' !== $to;
// Neither supplied: the caller wants the full priced span, which the persisted prices define.
if (!$hasFrom && !$hasTo) {
return;
}
// A lone dateFrom would have to mean "from there to the end of the prices", a third mode
// nobody asked for. Demand the pair instead of inventing a meaning for half of it.
if (!$hasFrom || !$hasTo) {
$context->buildViolation('dateFrom and dateTo must be supplied together.')
->atPath($hasFrom ? 'dateTo' : 'dateFrom')
->addViolation();
return;
}
$dateFrom = self::parseDate($from);
$dateTo = self::parseDate($to);
if (null === $dateFrom || null === $dateTo) {
return;
@@ -52,15 +71,29 @@ final readonly class ContingentCalendarQuery
}
}
public function dateFromDate(): \DateTimeImmutable
/**
* Null when the parameter was not supplied, which puts the request into full-span mode.
*/
public function dateFromDate(): ?\DateTimeImmutable
{
return self::parseDate($this->dateFrom)
?? throw new \LogicException('ContingentCalendarQuery must be validated before use.');
return $this->suppliedDate($this->dateFrom);
}
public function dateToDate(): \DateTimeImmutable
/**
* Null when the parameter was not supplied, which puts the request into full-span mode.
*/
public function dateToDate(): ?\DateTimeImmutable
{
return self::parseDate($this->dateTo)
return $this->suppliedDate($this->dateTo);
}
private function suppliedDate(?string $value): ?\DateTimeImmutable
{
if (null === $value || '' === $value) {
return null;
}
return self::parseDate($value)
?? throw new \LogicException('ContingentCalendarQuery must be validated before use.');
}