feat(clinic): enhance clinic detail response with location map and additional fields
This commit is contained in:
+22
-17
@@ -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 |
|
||||
|------|------|-------------|
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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,
|
||||
],
|
||||
|
||||
@@ -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')
|
||||
|
||||
Reference in New Issue
Block a user