feat(representation): add endpoints for doctor statistics and toggling doctor status

This commit is contained in:
hamed
2026-06-24 12:24:53 +03:30
parent 8b419d0272
commit b7df8cf9ee
3 changed files with 113 additions and 4 deletions
@@ -391,4 +391,64 @@ class RepresentationActionController extends BaseController
return $this->paginated($items, (int) $total, $page, $limit);
}
#[OA\Get(
path: '/api/v1/representation/doctors/stats',
summary: 'آمار پزشکانِ ثبت‌شده توسط نماینده‌ی جاری (شکلِ یکسان با /admin/doctors/stats)',
security: [['bearerAuth' => []]],
responses: [new OA\Response(response: 200, description: 'آمار پزشکان نماینده')]
)]
#[Route('/api/v1/representation/doctors/stats', methods: ['GET'])]
public function doctorStats(#[CurrentUser] User $user): JsonResponse
{
$rep = $this->representationRepo->findByUser($user);
if ($rep === null) {
return $this->error(ErrorCodes::ERR_NOT_FOUND_001, 'نماینده‌ای برای این کاربر یافت نشد', 404);
}
$conn = $this->em->getConnection();
$repId = $rep->getId();
$total = (int) $conn->fetchOne('SELECT COUNT(*) FROM doctors WHERE representation_id = ?', [$repId]);
$active = (int) $conn->fetchOne('SELECT COUNT(*) FROM doctors WHERE representation_id = ? AND active_doctor_appointment = 1', [$repId]);
$male = (int) $conn->fetchOne("SELECT COUNT(*) FROM doctors WHERE representation_id = ? AND gender IN ('man','male')", [$repId]);
$female = (int) $conn->fetchOne("SELECT COUNT(*) FROM doctors WHERE representation_id = ? AND gender IN ('woman','female')", [$repId]);
return $this->success([
'total' => $total,
'active' => $active,
'inactive' => $total - $active,
'male' => $male,
'female' => $female,
]);
}
#[OA\Post(
path: '/api/v1/representation/doctors/{uuid}/status',
summary: 'فعال/غیرفعال کردن پزشکِ زیرمجموعه‌ی نماینده‌ی جاری',
security: [['bearerAuth' => []]],
parameters: [new OA\Parameter(name: 'uuid', in: 'path', required: true, schema: new OA\Schema(type: 'string'))],
responses: [
new OA\Response(response: 200, description: 'وضعیت جدید پزشک'),
new OA\Response(response: 404, description: 'پزشک یافت نشد یا متعلق به این نماینده نیست'),
]
)]
#[Route('/api/v1/representation/doctors/{uuid}/status', methods: ['POST'])]
public function toggleDoctorStatus(string $uuid, #[CurrentUser] User $user): JsonResponse
{
$rep = $this->representationRepo->findByUser($user);
if ($rep === null) {
return $this->error(ErrorCodes::ERR_NOT_FOUND_001, 'نماینده‌ای برای این کاربر یافت نشد', 404);
}
$doctor = $this->em->getRepository(Doctor::class)->findOneBy(['uuid' => $uuid]);
if ($doctor === null || $doctor->getRepresentationId() !== $rep->getId()) {
return $this->error(ErrorCodes::ERR_NOT_FOUND_001, 'پزشک یافت نشد', 404);
}
$doctor->setActiveDoctorAppointment(!$doctor->isActiveDoctorAppointment());
$this->em->flush();
return $this->success(['is_active' => $doctor->isActiveDoctorAppointment()]);
}
}