feat(doctor): add filtering logic for clinic doctor list with pagination and sorting
This commit is contained in:
@@ -8,6 +8,7 @@ use App\Clinic\Entity\Clinic;
|
||||
use App\Clinic\Repository\ClinicRepository;
|
||||
use App\Doctor\Entity\Doctor;
|
||||
use App\Doctor\Entity\DoctorAddress;
|
||||
use App\Appointment\Repository\WeeklyScheduleRepository;
|
||||
use App\Doctor\Repository\DoctorAddressRepository;
|
||||
use App\Doctor\Repository\DoctorRepository;
|
||||
use App\DoctorService\Repository\DoctorServiceRepository;
|
||||
@@ -39,6 +40,7 @@ class ClinicController extends BaseController
|
||||
private readonly ProvinceRepository $provinceRepo,
|
||||
private readonly CityRepository $cityRepo,
|
||||
private readonly UserRepository $userRepo,
|
||||
private readonly WeeklyScheduleRepository $scheduleRepo,
|
||||
private readonly FileValidatorService $fileValidator,
|
||||
private readonly string $projectDir,
|
||||
) {}
|
||||
@@ -298,19 +300,34 @@ class ClinicController extends BaseController
|
||||
]
|
||||
)]
|
||||
#[Route('/api/v1/clinic/doctor-list/{clinicUuid}', methods: ['GET'])]
|
||||
public function doctorList(string $clinicUuid): JsonResponse
|
||||
public function doctorList(string $clinicUuid, Request $request): JsonResponse
|
||||
{
|
||||
$clinic = $this->clinicRepo->findByUuid($clinicUuid);
|
||||
if ($clinic === null) {
|
||||
return $this->error(ErrorCodes::ERR_VALIDATION_002, 'کلینیک یافت نشد', 404);
|
||||
}
|
||||
|
||||
$result = $this->doctorRepo->findByClinicWithFilters((int) $clinic->getId(), $request->query->all());
|
||||
$clinicDoctors = $result['items'];
|
||||
|
||||
$scheduleMap = [];
|
||||
foreach ($this->scheduleRepo->findByDoctors($clinicDoctors) as $schedule) {
|
||||
$scheduleMap[$schedule->getDoctor()->getId()] = $schedule;
|
||||
}
|
||||
|
||||
$doctors = array_map(
|
||||
fn(Doctor $d) => $d->toListArray(),
|
||||
$clinic->getDoctors()->toArray()
|
||||
fn(Doctor $d) => $d->toListArray($scheduleMap[$d->getId()] ?? null),
|
||||
$clinicDoctors
|
||||
);
|
||||
|
||||
return $this->success(['data' => $doctors]);
|
||||
return $this->success([
|
||||
'data' => $doctors,
|
||||
'meta' => [
|
||||
'totalRecords' => $result['total'],
|
||||
'totalPages' => $result['totalPages'],
|
||||
'currentPage' => $result['page'],
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
#[OA\Post(
|
||||
|
||||
Reference in New Issue
Block a user