feat: add recent dashboard data endpoint for appointments, payments, and users
This commit is contained in:
@@ -443,6 +443,73 @@ class AdminApiController extends BaseController
|
||||
return $this->paginated($items, (int) $total, $page, $limit);
|
||||
}
|
||||
|
||||
// ── Dashboard Recent ──────────────────────────────────────────────────────
|
||||
|
||||
#[Route('/api/v1/admin/dashboard/recent', methods: ['GET'])]
|
||||
public function dashboardRecent(): JsonResponse
|
||||
{
|
||||
$em = $this->em;
|
||||
|
||||
$recentAppointments = $em->createQueryBuilder()
|
||||
->select(
|
||||
'a.uuid, a.slotStart, a.status, a.createdAt',
|
||||
'd.name as doctor_name',
|
||||
'u.mobileNumber as user_mobile, u.realName as user_name'
|
||||
)
|
||||
->from(Appointment::class, 'a')
|
||||
->join('a.doctor', 'd')
|
||||
->join('a.user', 'u')
|
||||
->orderBy('a.createdAt', 'DESC')
|
||||
->setMaxResults(6)
|
||||
->getQuery()->getArrayResult();
|
||||
|
||||
$recentPayments = $em->createQueryBuilder()
|
||||
->select(
|
||||
'p.uuid, p.amountRials, p.status, p.gateway, p.createdAt',
|
||||
'u.mobileNumber as user_mobile, u.realName as user_name'
|
||||
)
|
||||
->from(Payment::class, 'p')
|
||||
->join('p.user', 'u')
|
||||
->orderBy('p.createdAt', 'DESC')
|
||||
->setMaxResults(6)
|
||||
->getQuery()->getArrayResult();
|
||||
|
||||
$recentUsers = $em->createQueryBuilder()
|
||||
->select('u.uuid, u.mobileNumber, u.realName, u.email, u.createdAt')
|
||||
->from(User::class, 'u')
|
||||
->orderBy('u.createdAt', 'DESC')
|
||||
->setMaxResults(6)
|
||||
->getQuery()->getArrayResult();
|
||||
|
||||
return $this->success([
|
||||
'appointments' => array_map(fn(array $a) => [
|
||||
'uuid' => $a['uuid'],
|
||||
'slot_start' => date('c', (int) $a['slotStart']),
|
||||
'status' => $a['status'],
|
||||
'doctor_name' => $a['doctor_name'],
|
||||
'user_mobile' => $a['user_mobile'],
|
||||
'user_name' => $a['user_name'],
|
||||
'created_at' => date('c', (int) $a['createdAt']),
|
||||
], $recentAppointments),
|
||||
'payments' => array_map(fn(array $p) => [
|
||||
'uuid' => $p['uuid'],
|
||||
'amount' => (int) $p['amountRials'],
|
||||
'status' => $p['status'],
|
||||
'gateway' => $p['gateway'],
|
||||
'user_mobile' => $p['user_mobile'],
|
||||
'user_name' => $p['user_name'],
|
||||
'created_at' => date('c', (int) $p['createdAt']),
|
||||
], $recentPayments),
|
||||
'users' => array_map(fn(array $u) => [
|
||||
'uuid' => $u['uuid'],
|
||||
'mobile' => $u['mobileNumber'],
|
||||
'name' => $u['realName'],
|
||||
'email' => $u['email'],
|
||||
'created_at' => date('c', (int) $u['createdAt']),
|
||||
], $recentUsers),
|
||||
]);
|
||||
}
|
||||
|
||||
// ── Dashboard Stats ───────────────────────────────────────────────────────
|
||||
|
||||
#[Route('/api/v1/admin/dashboard/stats', methods: ['GET'])]
|
||||
|
||||
Reference in New Issue
Block a user