From 89a8622e6a84b42e0bbd5e059cc1c57d7eb70270 Mon Sep 17 00:00:00 2001 From: hamed <15238-genius.ha@users.noreply.drupalcode.org> Date: Thu, 18 Jun 2026 15:21:24 +0330 Subject: [PATCH] feat(clinic): enhance clinic detail response with location map and additional fields --- docs/api/clinic.md | 39 +++++++++++-------- src/Clinic/Controller/ClinicController.php | 26 ++++++++----- src/Clinic/Entity/Clinic.php | 4 +- .../Repository/DoctorAddressRepository.php | 11 ++++++ 4 files changed, 51 insertions(+), 29 deletions(-) diff --git a/docs/api/clinic.md b/docs/api/clinic.md index cbd09f07..65a08f23 100644 --- a/docs/api/clinic.md +++ b/docs/api/clinic.md @@ -110,31 +110,36 @@ Get clinic detail. "success": true, "data": { "data": { + "id": "233", "uuid": "550e8400-...", "name": "کلینیک الوند", - "info": "...", - "address": "تهران، خیابان ولیعصر", - "telephone": "02112345678", - "working_days": "شنبه تا چهارشنبه", - "is_24_7": false, - "latitude": 35.6892, - "longitude": 51.3890, - "state": "تهران", - "city": "تهران", - "images_clinic": [{ "url": "https://..." }], - "clinic_logo": "https://...", + "title": "کلینیک الوند", "is_active": true, - "doctors": [{ "uuid": "...", "title": "دکتر..." }], - "specialties": [{ "id": 1, "name": "قلب" }], - "doctor_services": [], - "insurance": [], - "tags": [], - "owner": { "uuid": "...", "real_name": "..." } + "phone": "02112345678", + "phone_number": "02112345678", + "logo": "/uploads/clinics/logo/...", + "clinic_logo": "/uploads/clinics/logo/...", + "images_clinic": [{ "url": "/uploads/clinics/gallery/..." }], + "caption": "توضیحات کلینیک", + "list_bime": [], + "specialties": [{ "uuid": "...", "id": "1", "name": "قلب", "parent": null }], + "services": [], + "clinic_specialty": [{ "uuid": "...", "id": "1", "name": "قلب", "parent": null }], + "doctors": 5, + "doctor_list": null, + "city": [{ "uuid": "...", "id": "132", "name": "یزد", "parent": "100" }], + "state": [{ "uuid": "...", "id": "100", "name": "یزد" }], + "location": "یزد، خیابان اصلی، پلاک 101", + "map": { "latitude": "31.868", "longitude": "54.330" }, + "24_7": false, + "field_working_days": "شنبه تا پنجشنبه ۸ تا ۱۸" } } } ``` +> `city`/`state`/`map` are resolved from the clinic's **address** (`DoctorAddress` linked by `clinic_id`), not from columns on the clinic. Each is an array with a single object (or empty `[]` if the clinic has no address). `doctors` is a **count**; the actual doctor list comes from `GET /api/v1/clinic/doctor-list/{clinicUuid}` (`doctor_list` here is always `null`). + ### Errors | Code | HTTP | Description | |------|------|-------------| diff --git a/src/Clinic/Controller/ClinicController.php b/src/Clinic/Controller/ClinicController.php index 0d093328..3b967428 100644 --- a/src/Clinic/Controller/ClinicController.php +++ b/src/Clinic/Controller/ClinicController.php @@ -137,9 +137,9 @@ class ClinicController extends BaseController return $this->error(ErrorCodes::ERR_VALIDATION_002, 'کلینیک یافت نشد', 404); } - [$stateData, $cityData] = $this->loadLocationData($clinic); + [$stateData, $cityData, $map] = $this->loadLocationData($clinic); - return $this->success(['data' => $clinic->toDetailArray($stateData, $cityData)]); + return $this->success(['data' => $clinic->toDetailArray($stateData, $cityData, $map)]); } #[OA\Patch( @@ -210,9 +210,9 @@ class ClinicController extends BaseController $this->hydrateClinic($clinic, $data); $this->clinicRepo->save($clinic); - [$stateData, $cityData] = $this->loadLocationData($clinic); + [$stateData, $cityData, $map] = $this->loadLocationData($clinic); - return $this->success(['data' => $clinic->toDetailArray($stateData, $cityData)]); + return $this->success(['data' => $clinic->toDetailArray($stateData, $cityData, $map)]); } #[OA\Get( @@ -486,15 +486,17 @@ class ClinicController extends BaseController { $provinceData = []; $cityData = []; + $map = ['latitude' => null, 'longitude' => null]; - if ($clinic->getProvinceId() !== null) { - $province = $this->provinceRepo->find($clinic->getProvinceId()); + // City/province/coordinates live on the clinic's address (DoctorAddress + // linked by clinicId), not on the deprecated columns of the clinic itself. + $address = $this->addressRepo->findOneByClinic((int) $clinic->getId()); + if ($address !== null) { + $province = $address->getProvince(); if ($province !== null) { $provinceData = ['uuid' => $province->getUuid(), 'id' => (string) $province->getId(), 'name' => $province->getName()]; } - } - if ($clinic->getCityId() !== null) { - $city = $this->cityRepo->find($clinic->getCityId()); + $city = $address->getCity(); if ($city !== null) { $cityData = [ 'uuid' => $city->getUuid(), @@ -503,9 +505,13 @@ class ClinicController extends BaseController 'parent' => $city->getProvince()?->getId() !== null ? (string) $city->getProvince()->getId() : null, ]; } + $map = [ + 'latitude' => $address->getLatitude() !== null ? (string) $address->getLatitude() : null, + 'longitude' => $address->getLongitude() !== null ? (string) $address->getLongitude() : null, + ]; } - return [$provinceData, $cityData]; + return [$provinceData, $cityData, $map]; } private function handleFileUpload(Request $request, string $subDir): JsonResponse diff --git a/src/Clinic/Entity/Clinic.php b/src/Clinic/Entity/Clinic.php index 81c28431..cc7d024d 100644 --- a/src/Clinic/Entity/Clinic.php +++ b/src/Clinic/Entity/Clinic.php @@ -169,7 +169,7 @@ class Clinic private function touch(): void { $this->updatedAt = time(); } - public function toDetailArray(array $provinceData = [], array $cityData = []): array + public function toDetailArray(array $provinceData = [], array $cityData = [], ?array $map = null): array { return [ 'id' => (string) $this->id, @@ -202,7 +202,7 @@ class Clinic 'city' => $cityData ? [$cityData] : [], 'state' => $provinceData ? [$provinceData] : [], 'location' => $this->address, - 'map' => [ + 'map' => $map ?? [ 'latitude' => $this->latitude !== null ? (string) $this->latitude : null, 'longitude' => $this->longitude !== null ? (string) $this->longitude : null, ], diff --git a/src/Doctor/Repository/DoctorAddressRepository.php b/src/Doctor/Repository/DoctorAddressRepository.php index 0d96251d..49777daf 100644 --- a/src/Doctor/Repository/DoctorAddressRepository.php +++ b/src/Doctor/Repository/DoctorAddressRepository.php @@ -41,6 +41,17 @@ class DoctorAddressRepository extends ServiceEntityRepository ->getOneOrNullResult(); } + public function findOneByClinic(int $clinicId): ?DoctorAddress + { + return $this->createQueryBuilder('a') + ->where('a.clinicId = :clinicId') + ->setParameter('clinicId', $clinicId) + ->orderBy('a.id', 'ASC') + ->setMaxResults(1) + ->getQuery() + ->getOneOrNullResult(); + } + public function countByClinic(int $clinicId): int { return (int) $this->createQueryBuilder('a')