# معماری — تسک ۱۰: مدیریت پرسنل (Staff) ## ساختار فایل‌ها ``` src/Staff/ ├── Controller/ │ └── StaffController.php ├── Entity/ │ └── ClinicStaff.php ├── Repository/ │ └── ClinicStaffRepository.php └── Service/ └── StaffService.php ``` ## Entity: ClinicStaff ```php uuid = (string) Uuid::v4(); $this->createdAt = time(); $this->updatedAt = time(); } // getters/setters ... } ``` ## Controller: StaffController ```php success($items); } #[Route('/staff', methods: ['POST'])] public function create(Request $request): JsonResponse { // 1. validate: full_name اجباری // 2. ClinicStaff جدید با entityType/entityId از JWT بساز // 3. persist و flush // 4. return $this->success($staff->toArray()); } #[Route('/staff/{uuid}', methods: ['PATCH'])] public function update(string $uuid, Request $request): JsonResponse { // 1. find by uuid → 404 اگر نبود // 2. بررسی مالکیت: staff->entityType/entityId == JWT claim → 403 اگر نبود // 3. ویرایش فیلدهای موجود در body // 4. return $this->success($staff->toArray()); } #[Route('/staff/{uuid}/toggle', methods: ['PATCH'])] public function toggle(string $uuid): JsonResponse { // 1. find → ownership check // 2. active = !active // 3. return $this->success(['active' => $staff->isActive()]); } } ``` ## Service: StaffService ```php $staff->getUuid(), 'full_name' => $staff->getFullName(), 'phone' => $staff->getPhone(), 'job_title' => $staff->getJobTitle(), 'address' => $staff->getAddress(), 'national_code' => $staff->getNationalCode(), 'active' => $staff->isActive(), 'created_at' => $staff->getCreatedAt(), ]; } } ``` ## نحوه خواندن entity_type / entity_id از JWT ```php // در BaseController یا trait: // JWT payload شامل: db_key ('doctor'/'clinic') و db_uuid (uuid entity) // باید uuid را به id تبدیل کنیم: $entityType = $this->getUser()->getDbKey(); // 'doctor' یا 'clinic' $entityUuid = $this->getUser()->getDbUuid(); // سپس از Repository مربوطه id واقعی را بگیریم ``` ## وابستگی‌های آینده - `src/ClinicService/Entity/ServiceItem.php` → `staff_id FK → clinic_staff.id` - `src/Patient/Entity/SessionService.php` → `staff_id FK → clinic_staff.id`