feat: add clinic status management with active/inactive toggle and update related API endpoints

This commit is contained in:
hamed
2026-06-10 21:29:29 +03:30
parent b0d6ecbd96
commit c41d03b5c5
6 changed files with 555 additions and 134 deletions
@@ -428,6 +428,86 @@ class AdminApiController extends BaseController
return $this->success(['uuid' => $doctor->getUuid()], 201);
}
// ── Clinics ───────────────────────────────────────────────────────────────
#[Route('/api/v1/admin/clinics', methods: ['GET'])]
public function clinicsList(Request $request): JsonResponse
{
$page = max(1, (int) $request->query->get('page', 1));
$limit = min(100, max(5, (int) $request->query->get('limit', 15)));
$search = trim((string) $request->query->get('search', ''));
$status = $request->query->get('status', '');
$conn = $this->em->getConnection();
$where = ['1=1'];
$params = [];
if ($search !== '') {
$where[] = '(c.name LIKE :s OR c.telephone LIKE :s)';
$params['s'] = '%' . $search . '%';
}
if ($status !== '') {
$where[] = 'c.is_active = :active';
$params['active'] = $status === '1' ? 1 : 0;
}
$whereStr = implode(' AND ', $where);
$total = (int) $conn->fetchOne(
"SELECT COUNT(*) FROM clinics c WHERE $whereStr",
$params
);
$offset = ($page - 1) * $limit;
$rows = $conn->fetchAllAssociative(
"SELECT c.uuid, c.name, c.telephone, c.clinic_logo, c.is_active, c.created_at,
COUNT(DISTINCT cd.doctor_id) as doctors_count
FROM clinics c
LEFT JOIN clinic_doctors cd ON cd.clinic_id = c.id
WHERE $whereStr
GROUP BY c.id
ORDER BY c.created_at DESC
LIMIT $limit OFFSET $offset",
$params
);
$items = array_map(fn(array $c) => [
'uuid' => $c['uuid'],
'name' => $c['name'],
'phone' => $c['telephone'],
'logo' => $c['clinic_logo'],
'is_active' => (bool) $c['is_active'],
'doctors_count' => (int) $c['doctors_count'],
'created_at' => (int) $c['created_at'],
], $rows);
return $this->paginated($items, $total, $page, $limit);
}
#[Route('/api/v1/admin/clinic/{uuid}/status', methods: ['PATCH'])]
public function toggleClinicStatus(string $uuid): JsonResponse
{
$clinic = $this->em->getRepository(Clinic::class)->findOneBy(['uuid' => $uuid]);
if (!$clinic) return $this->error('CLINIC_NOT_FOUND', 'کلینیک یافت نشد', 404);
$clinic->setIsActive(!$clinic->isActive());
$this->em->flush();
return $this->success(['is_active' => $clinic->isActive()]);
}
#[Route('/api/v1/admin/clinic/{uuid}', methods: ['DELETE'])]
public function deleteClinic(string $uuid): JsonResponse
{
$clinic = $this->em->getRepository(Clinic::class)->findOneBy(['uuid' => $uuid]);
if (!$clinic) return $this->error('CLINIC_NOT_FOUND', 'کلینیک یافت نشد', 404);
$this->em->remove($clinic);
$this->em->flush();
return $this->success(null);
}
// ── Appointments ──────────────────────────────────────────────────────────
#[OA\Get(