refactor(branch): remove the branch domain, keep the address

Branches and rooms are not part of the resource-first product: a room is a
resource like any other, and the only thing the branch pages still managed —
opening hours — duplicated the resource's own shift.

What could not go is the address. Every appointment carries address_id (75 of
75 rows), the public booking site reads /clinic-pro/doctor-address/{id}, and a
resource derives its tenant pair from the address it belongs to. So
DoctorAddress stays as an invisible anchor with no page and no menu entry, and
GET /api/v1/addresses replaces GET /api/v1/branches for the forms that still
need to say "where".

BranchResolver was likewise not a branch feature. doctor_addresses is a global
table, so TenantFilter does not cover it and eight callers across booking,
availability, pricing and the catalog went through this resolver to avoid
leaking another clinic's address. It moved to Doctor\Service\AddressResolver
rather than dying with the domain.

The availability engine loses one layer: a resource's real hours were the
branch hours intersected with its shift, and are now the shift alone. That is
the single behavioural change, and the three tests that asserted the old
contract are replaced by one that states the new one.

Rooms already had a resource row each; the migration drops only the bridge
back to `rooms`, and drops it before the table — that foreign key is ON DELETE
CASCADE and the other order would take the resources, and their appointments,
with it.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
hamed
2026-08-02 15:25:32 +03:30
co-authored by Claude Opus 5
parent 1c4f2a2451
commit dd284ec622
59 changed files with 566 additions and 3128 deletions
+10 -14
View File
@@ -11,10 +11,11 @@
## کسرِ لایه‌ها
بند ۹ مستند ساعت آزاد را از کسر هفت لایه می‌سازد. آنچه این بخش می‌دهد **چهار لایهٔ اول** است:
بند ۹ مستند ساعت آزاد را از کسر هفت لایه می‌سازد. آنچه این بخش می‌دهد **سه لایهٔ اول** است
(لایهٔ «ساعت کاری شعبه» با حذف دامنهٔ شعبه برداشته شد — تنها مرجع ساعت، شیفت خودِ منبع است):
```
ساعت کاری شعبه ∩ شیفت منبع − تعطیلات رسمی − استثناهای منبع
شیفت منبع − تعطیلات رسمی − استثناهای منبع
```
**نوبت‌های ثبت‌شده و رزروهای موقت اینجا کسر نمی‌شوند.** خروجی این اندپوینت «وقت قابل
@@ -44,13 +45,13 @@
}
```
`days` همیشه **شیء** با هر هفت کلید `"0".."6"` است؛ ۰ = شنبه. `timezone` از شعبهٔ منبع
`days` همیشه **شیء** با هر هفت کلید `"0".."6"` است؛ ۰ = شنبه. `timezone` از محل نوبت‌دهی منبع
می‌آید و مبنای «روز» در محاسبهٔ ساعت آزاد است.
## `PUT /api/v1/resource/{uuid}/calendar`
جایگزینی کامل هفت روز — روزی که نفرستید خالی می‌شود. قواعد و خطاها دقیقاً مثل ساعت
کاری شعبه ([branch.md](branch.md)): دقیقه از نیمه‌شب `0..1440`، `end > start`، بدون
کاری: دقیقه از نیمه‌شب `0..1440`، `end > start`، بدون
هم‌پوشانی در یک روز، `sequence` را سرور می‌دهد، و **اعتبارسنجی کامل پیش از هر حذفی**.
```json
@@ -136,12 +137,10 @@
| کد | یعنی |
|---|---|
| `no_shift` | منبع آن روز شیفتی ندارد |
| `branch_closed` | شعبه آن روز ساعت کاری ندارد |
| `outside_branch_hours` | شیفت هست ولی تقاطعش با ساعت شعبه خالی شد |
| `national_holiday` | تعطیل رسمی کشور |
| `tenant_holiday` | این محیط آن روز را تعطیل اعلام کرده |
| `exception` | مرخصی/غیبت/سرویس بخشی یا تمام روز را بریده |
| `resource_inactive` / `branch_inactive` | منبع یا شعبه غیرفعال است |
| `resource_inactive` / `address_inactive` | منبع یا محل نوبت‌دهی غیرفعال است |
**۴۲۲:** نبودِ `from`/`to` · `to < from` · بازهٔ بیش از ۹۲ روز (خروجی واقعی):
@@ -149,14 +148,11 @@
{"success":false,"data":null,"errors":[{"code":"ERR_VALIDATION_001","message":"بازهٔ درخواستی حداکثر 92 روز است","field":"to"}]}
```
### دو قرارداد مهم
### یک قرارداد مهم
**شعبهٔ بدون ساعت کاری = «تعریف‌نشده»، نه «بسته».** شیفت منبع بی‌قید اعمال می‌شود تا
دادهٔ موجود دقیقاً مثل امروز کار کند. این با `branch_closed` — که یعنی ساعت تعریف شده
ولی آن روز خالی است — فرق دارد.
**شیفت بیرون از ساعت شعبه رد نمی‌شود، تقاطع گرفته می‌شود.** شیفت ۹–۱۷ روی شعبه‌ای که
۱۰–۱۲ باز است، ۱۲۰ دقیقه می‌دهد.
**تنها مرجع ساعت کاری، شیفت خودِ منبع است.** تا پیش از حذف دامنهٔ شعبه، این شیفت با
ساعت کاری شعبه تقاطع می‌گرفت و دلیل‌های `branch_closed` و `outside_branch_hours` را
می‌ساخت؛ آن لایه و آن دو دلیل دیگر وجود ندارند.
---