feat(appointment): store online-booking window in WeeklySchedule meta

Add a reserved meta key inside WeeklySchedule.setting (no migration) holding
online_booking_enabled and a booking_window value+unit (week|month), with
sane defaults. Expose meta separately in toArray() and keep it out of the
day schedule map. setSetting now preserves meta when the day schedule is
replaced; the weekly-schedule POST/PATCH endpoints accept an optional meta.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
hamed
2026-06-15 16:16:30 +03:30
co-authored by Claude Opus 4.8
parent c662eb9b4f
commit 09aba878f8
3 changed files with 229 additions and 2 deletions
+46 -2
View File
@@ -13,6 +13,13 @@ class WeeklySchedule
{
public const DAYS = ['saturday', 'sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday'];
public const META_KEY = 'meta';
public const DEFAULT_META = [
'online_booking_enabled' => true,
'booking_window_value' => 1,
'booking_window_unit' => 'month',
];
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
@@ -48,14 +55,51 @@ class WeeklySchedule
public function getDoctor(): Doctor { return $this->doctor; }
public function getSetting(): array { return $this->setting; }
public function setSetting(array $setting): self { $this->setting = $setting; $this->updatedAt = time(); return $this; }
public function setSetting(array $setting): self
{
$meta = $this->setting[self::META_KEY] ?? null;
unset($setting[self::META_KEY]);
if ($meta !== null) {
$setting[self::META_KEY] = $meta;
}
$this->setting = $setting;
$this->updatedAt = time();
return $this;
}
public function getMeta(): array
{
return array_merge(self::DEFAULT_META, $this->setting[self::META_KEY] ?? []);
}
public function setMeta(array $meta): self
{
$current = $this->getMeta();
$this->setting[self::META_KEY] = [
'online_booking_enabled' => (bool)($meta['online_booking_enabled'] ?? $current['online_booking_enabled']),
'booking_window_value' => max(1, (int)($meta['booking_window_value'] ?? $current['booking_window_value'])),
'booking_window_unit' => in_array($meta['booking_window_unit'] ?? null, ['week', 'month'], true)
? $meta['booking_window_unit']
: $current['booking_window_unit'],
];
$this->updatedAt = time();
return $this;
}
public function getDaySchedule(): array
{
$schedule = $this->setting;
unset($schedule[self::META_KEY]);
return $schedule;
}
public function toArray(): array
{
return [
'uuid' => $this->uuid,
'doctor_uuid' => $this->doctor->getUuid(),
'schedule' => $this->setting,
'schedule' => $this->getDaySchedule(),
'meta' => $this->getMeta(),
'created_at' => $this->createdAt,
'updated_at' => $this->updatedAt,
];