feat(clinic): enhance clinic detail response with location map and additional fields
This commit is contained in:
@@ -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