# نکات پیاده‌سازی — تسک ۰۳: ماژول پروفایل کاربر ## جریان بعد از ذخیره پروفایل طبق مستندات Drupal، بعد از ذخیره پروفایل باید: 1. `POST /oauth/token` با refresh_token اجرا شود (دریافت access_token جدید) 2. `GET /oauth/userinfo` اجرا شود در Symfony این جریان در سمت **کلاینت** انجام می‌شود، نه سرور. → در پاسخ POST /api/v1/user-profile، token های به‌روز شده نیز برگردان: ```json { "data": { "profile": { "uuid": "...", "name": "..." }, "access_token": "eyJ...", "refresh_token": "eyJ..." }, "message": "پروفایل با موفقیت ذخیره شد" } ``` ## اعتبارسنجی blood_type مقادیر مجاز: ```php #[Assert\Choice(choices: [ 'a_positive', 'a_negative', 'b_positive', 'b_negative', 'ab_positive', 'ab_negative', 'o_positive', 'o_negative' ])] ``` ## اعتبارسنجی gender ```php #[Assert\Choice(choices: ['male', 'female', 'other'])] ``` ## اعتبارسنجی education ```php #[Assert\Choice(choices: [ 'primary', 'secondary', 'diploma', 'associate', 'bachelor', 'master', 'postgraduate_diploma', 'doctorate' ])] ``` ## Partial Update (PATCH) endpoint PATCH باید فقط فیلدهایی که ارسال شده را آپدیت کند. → از `$request->request->has('field')` یا DTO با nullable fields استفاده کن. → مثال: اگر فقط `diseases` در body باشد، بقیه فیلدها تغییر نکنند. ## مجوزها ``` POST /api/v1/user-profile → کاربر احراز هویت‌شده (برای خودش) GET /api/v1/user-profile/{uuid} → owner یا ROLE_ADMIN یا ROLE_DOCTOR (دکتر مرتبط) PATCH /api/v1/user-profile/{uuid} → owner یا ROLE_ADMIN DELETE /api/v1/user-profile/{uuid} → فقط ROLE_ADMIN ``` ## نکته UUID در URL در Drupal از UUID واقعی در URL استفاده می‌شد. در Symfony نیز همان رویکرد حفظ می‌شود. ParamConverter می‌تواند UUID را به Entity تبدیل کند: ```php #[Route('/api/v1/user-profile/{uuid}', methods: ['GET'])] public function get(UserProfile $userProfile): Response // Doctrine ParamConverter به طور خودکار uuid را به UserProfile تبدیل می‌کند ```