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:
@@ -9,6 +9,10 @@ use App\Appointment\Repository\DateOverrideRepository;
|
||||
use App\Appointment\Repository\HolidayRepository;
|
||||
use App\Appointment\Repository\WeeklyScheduleRepository;
|
||||
use App\Auth\Entity\User;
|
||||
use App\Clinic\Entity\Clinic;
|
||||
use App\Clinic\Repository\ClinicRepository;
|
||||
use App\Doctor\Entity\DoctorAddress;
|
||||
use App\Doctor\Repository\DoctorAddressRepository;
|
||||
use App\Doctor\Repository\DoctorRepository;
|
||||
use App\Shared\Constant\ErrorCodes;
|
||||
use App\Shared\Controller\BaseController;
|
||||
@@ -26,6 +30,8 @@ class AppointmentSettingsController extends BaseController
|
||||
private readonly DateOverrideRepository $overrideRepo,
|
||||
private readonly HolidayRepository $holidayRepo,
|
||||
private readonly DoctorRepository $doctorRepo,
|
||||
private readonly DoctorAddressRepository $addressRepo,
|
||||
private readonly ClinicRepository $clinicRepo,
|
||||
) {}
|
||||
|
||||
// ── Weekly Schedule ───────────────────────────────────────────────────────
|
||||
@@ -313,4 +319,32 @@ class AppointmentSettingsController extends BaseController
|
||||
|
||||
return $this->success(['data' => $holiday->toArray()]);
|
||||
}
|
||||
|
||||
// ── Available Locations ───────────────────────────────────────────────────
|
||||
|
||||
#[Route('/api/v1/appointment-settings/available-locations/{doctorUuid}', methods: ['GET'])]
|
||||
public function availableLocations(string $doctorUuid): JsonResponse
|
||||
{
|
||||
$doctor = $this->doctorRepo->findByUuid($doctorUuid);
|
||||
if ($doctor === null) {
|
||||
return $this->error(ErrorCodes::ERR_VALIDATION_002, 'دکتر یافت نشد', 404);
|
||||
}
|
||||
|
||||
$clinics = $this->clinicRepo->findByDoctor($doctor);
|
||||
$clinicIds = array_map(fn(Clinic $c) => $c->getId(), $clinics);
|
||||
$clinicMap = [];
|
||||
foreach ($clinics as $clinic) {
|
||||
$clinicMap[$clinic->getId()] = $clinic->getName();
|
||||
}
|
||||
|
||||
$addresses = $this->addressRepo->findAvailableForDoctor($doctor, $clinicIds);
|
||||
|
||||
$result = array_map(function (DoctorAddress $a) use ($clinicMap): array {
|
||||
$data = $a->toArray();
|
||||
$data['clinic_name'] = $a->getClinicId() !== null ? ($clinicMap[$a->getClinicId()] ?? null) : null;
|
||||
return $data;
|
||||
}, $addresses);
|
||||
|
||||
return $this->success(['data' => $result]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user