feat: enhance DoctorAddress entity to support clinic addresses and types

- Added `clinic_id` and `type` fields to `DoctorAddress` entity to differentiate between personal and clinic addresses.
- Updated constructor to support creation of addresses for both doctors and clinics.
- Modified repository methods to handle new address types and added methods for counting and finding addresses by clinic.
- Implemented migration to update the database schema accordingly.
- Removed deprecated endpoint for creating addresses from clinics and updated related controller methods.
- Added new endpoints for managing clinic addresses, including CRUD operations.
- Updated frontend components to handle new address types and display accordingly.
This commit is contained in:
hamed
2026-06-12 13:39:37 +03:30
parent 63073c6a42
commit 0333b24071
13 changed files with 1446 additions and 89 deletions
+11 -51
View File
@@ -469,7 +469,7 @@ class DoctorController extends BaseController
}
}
$address = new DoctorAddress($doctor);
$address = DoctorAddress::forDoctor($doctor);
$this->hydrateAddress($address, $data);
$this->addressRepo->save($address);
@@ -554,7 +554,11 @@ class DoctorController extends BaseController
return $this->error(ErrorCodes::ERR_VALIDATION_002, 'آدرس یافت نشد', 404);
}
if ($address->getDoctor()->getUser()->getId() !== $user->getId() && !$user->hasRole('ROLE_ADMIN')) {
if ($address->getType() !== DoctorAddress::TYPE_PERSONAL) {
return $this->error(ErrorCodes::ERR_AUTH_006, 'آدرس کلینیک از طریق مدیریت کلینیک ویرایش می‌شود', 403);
}
if ($address->getDoctor()?->getUser()->getId() !== $user->getId() && !$user->hasRole('ROLE_ADMIN')) {
return $this->error(ErrorCodes::ERR_AUTH_006, 'دسترسی ممنوع', 403);
}
@@ -599,7 +603,11 @@ class DoctorController extends BaseController
return $this->error(ErrorCodes::ERR_VALIDATION_002, 'آدرس یافت نشد', 404);
}
if ($address->getDoctor()->getUser()->getId() !== $user->getId() && !$user->hasRole('ROLE_ADMIN')) {
if ($address->getType() !== DoctorAddress::TYPE_PERSONAL) {
return $this->error(ErrorCodes::ERR_AUTH_006, 'آدرس کلینیک از طریق مدیریت کلینیک حذف می‌شود', 403);
}
if ($address->getDoctor()?->getUser()->getId() !== $user->getId() && !$user->hasRole('ROLE_ADMIN')) {
return $this->error(ErrorCodes::ERR_AUTH_006, 'دسترسی ممنوع', 403);
}
@@ -724,52 +732,4 @@ class DoctorController extends BaseController
}
}
#[Route('/api/v1/clinic-pro/doctor-address/from-clinic/{clinicUuid}', methods: ['POST'])]
#[IsGranted('IS_AUTHENTICATED_FULLY')]
public function createAddressFromClinic(string $clinicUuid, #[CurrentUser] User $user): JsonResponse
{
$doctor = $this->doctorRepo->findByUser($user);
if ($doctor === null) {
return $this->error(ErrorCodes::ERR_AUTH_006, 'فقط دکتر می‌تواند آدرس اضافه کند', 403);
}
$clinic = $this->clinicRepo->findByUuid($clinicUuid);
if ($clinic === null) {
return $this->error(ErrorCodes::ERR_VALIDATION_002, 'کلینیک یافت نشد', 404);
}
// Verify doctor belongs to this clinic
$clinics = $this->clinicRepo->findByDoctor($doctor);
$belongs = array_filter($clinics, fn(Clinic $c) => $c->getUuid() === $clinicUuid);
if (empty($belongs)) {
return $this->error(ErrorCodes::ERR_AUTH_006, 'این دکتر عضو این کلینیک نیست', 403);
}
// Prevent duplicate: if this doctor already has an address for this clinic (same name), skip
foreach ($doctor->getAddresses() as $existing) {
if ($existing->getName() === $clinic->getName()) {
return $this->success(['data' => $existing->toArray()]);
}
}
$address = new DoctorAddress($doctor);
$address->setName($clinic->getName());
$address->setAddress($clinic->getAddress());
$address->setTelephone($clinic->getTelephone());
$address->setLatitude($clinic->getLatitude());
$address->setLongitude($clinic->getLongitude());
if ($clinic->getCityId() !== null) {
$city = $this->cityRepo->find($clinic->getCityId());
$address->setCity($city);
}
if ($clinic->getProvinceId() !== null) {
$province = $this->provinceRepo->find($clinic->getProvinceId());
$address->setProvince($province);
}
$this->addressRepo->save($address);
return $this->success(['data' => $address->toArray()], 201);
}
}