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,
|
"success": true,
|
||||||
"data": {
|
"data": {
|
||||||
"data": {
|
"data": {
|
||||||
|
"id": "233",
|
||||||
"uuid": "550e8400-...",
|
"uuid": "550e8400-...",
|
||||||
"name": "کلینیک الوند",
|
"name": "کلینیک الوند",
|
||||||
"info": "...",
|
"title": "کلینیک الوند",
|
||||||
"address": "تهران، خیابان ولیعصر",
|
|
||||||
"telephone": "02112345678",
|
|
||||||
"working_days": "شنبه تا چهارشنبه",
|
|
||||||
"is_24_7": false,
|
|
||||||
"latitude": 35.6892,
|
|
||||||
"longitude": 51.3890,
|
|
||||||
"state": "تهران",
|
|
||||||
"city": "تهران",
|
|
||||||
"images_clinic": [{ "url": "https://..." }],
|
|
||||||
"clinic_logo": "https://...",
|
|
||||||
"is_active": true,
|
"is_active": true,
|
||||||
"doctors": [{ "uuid": "...", "title": "دکتر..." }],
|
"phone": "02112345678",
|
||||||
"specialties": [{ "id": 1, "name": "قلب" }],
|
"phone_number": "02112345678",
|
||||||
"doctor_services": [],
|
"logo": "/uploads/clinics/logo/...",
|
||||||
"insurance": [],
|
"clinic_logo": "/uploads/clinics/logo/...",
|
||||||
"tags": [],
|
"images_clinic": [{ "url": "/uploads/clinics/gallery/..." }],
|
||||||
"owner": { "uuid": "...", "real_name": "..." }
|
"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
|
### Errors
|
||||||
| Code | HTTP | Description |
|
| Code | HTTP | Description |
|
||||||
|------|------|-------------|
|
|------|------|-------------|
|
||||||
|
|||||||
@@ -137,9 +137,9 @@ class ClinicController extends BaseController
|
|||||||
return $this->error(ErrorCodes::ERR_VALIDATION_002, 'کلینیک یافت نشد', 404);
|
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(
|
#[OA\Patch(
|
||||||
@@ -210,9 +210,9 @@ class ClinicController extends BaseController
|
|||||||
$this->hydrateClinic($clinic, $data);
|
$this->hydrateClinic($clinic, $data);
|
||||||
$this->clinicRepo->save($clinic);
|
$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(
|
#[OA\Get(
|
||||||
@@ -486,15 +486,17 @@ class ClinicController extends BaseController
|
|||||||
{
|
{
|
||||||
$provinceData = [];
|
$provinceData = [];
|
||||||
$cityData = [];
|
$cityData = [];
|
||||||
|
$map = ['latitude' => null, 'longitude' => null];
|
||||||
|
|
||||||
if ($clinic->getProvinceId() !== null) {
|
// City/province/coordinates live on the clinic's address (DoctorAddress
|
||||||
$province = $this->provinceRepo->find($clinic->getProvinceId());
|
// 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) {
|
if ($province !== null) {
|
||||||
$provinceData = ['uuid' => $province->getUuid(), 'id' => (string) $province->getId(), 'name' => $province->getName()];
|
$provinceData = ['uuid' => $province->getUuid(), 'id' => (string) $province->getId(), 'name' => $province->getName()];
|
||||||
}
|
}
|
||||||
}
|
$city = $address->getCity();
|
||||||
if ($clinic->getCityId() !== null) {
|
|
||||||
$city = $this->cityRepo->find($clinic->getCityId());
|
|
||||||
if ($city !== null) {
|
if ($city !== null) {
|
||||||
$cityData = [
|
$cityData = [
|
||||||
'uuid' => $city->getUuid(),
|
'uuid' => $city->getUuid(),
|
||||||
@@ -503,9 +505,13 @@ class ClinicController extends BaseController
|
|||||||
'parent' => $city->getProvince()?->getId() !== null ? (string) $city->getProvince()->getId() : null,
|
'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
|
private function handleFileUpload(Request $request, string $subDir): JsonResponse
|
||||||
|
|||||||
@@ -169,7 +169,7 @@ class Clinic
|
|||||||
|
|
||||||
private function touch(): void { $this->updatedAt = time(); }
|
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 [
|
return [
|
||||||
'id' => (string) $this->id,
|
'id' => (string) $this->id,
|
||||||
@@ -202,7 +202,7 @@ class Clinic
|
|||||||
'city' => $cityData ? [$cityData] : [],
|
'city' => $cityData ? [$cityData] : [],
|
||||||
'state' => $provinceData ? [$provinceData] : [],
|
'state' => $provinceData ? [$provinceData] : [],
|
||||||
'location' => $this->address,
|
'location' => $this->address,
|
||||||
'map' => [
|
'map' => $map ?? [
|
||||||
'latitude' => $this->latitude !== null ? (string) $this->latitude : null,
|
'latitude' => $this->latitude !== null ? (string) $this->latitude : null,
|
||||||
'longitude' => $this->longitude !== null ? (string) $this->longitude : null,
|
'longitude' => $this->longitude !== null ? (string) $this->longitude : null,
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -41,6 +41,17 @@ class DoctorAddressRepository extends ServiceEntityRepository
|
|||||||
->getOneOrNullResult();
|
->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
|
public function countByClinic(int $clinicId): int
|
||||||
{
|
{
|
||||||
return (int) $this->createQueryBuilder('a')
|
return (int) $this->createQueryBuilder('a')
|
||||||
|
|||||||
Reference in New Issue
Block a user