Fix: Add pagination to admin appointments endpoint
- Added pagination with page/per_page query params - Fixed N+1 query by using eager-loaded user relationship - Removed unused _get_user_email helper function - Updated frontend to handle paginated response - Regenerated API types
This commit is contained in:
parent
1cd60b4bbc
commit
77e7f98e1e
4 changed files with 70 additions and 28 deletions
|
|
@ -9,6 +9,7 @@ import { useRequireAuth } from "../../hooks/useRequireAuth";
|
|||
import { components } from "../../generated/api";
|
||||
|
||||
type AppointmentResponse = components["schemas"]["AppointmentResponse"];
|
||||
type PaginatedAppointments = components["schemas"]["PaginatedResponse_AppointmentResponse_"];
|
||||
|
||||
// Helper to format datetime
|
||||
function formatDateTime(isoString: string): string {
|
||||
|
|
@ -200,8 +201,9 @@ export default function AdminAppointmentsPage() {
|
|||
|
||||
const fetchAppointments = useCallback(async () => {
|
||||
try {
|
||||
const data = await api.get<AppointmentResponse[]>("/api/admin/appointments");
|
||||
setAppointments(data);
|
||||
// Fetch with large per_page to get all appointments for now
|
||||
const data = await api.get<PaginatedAppointments>("/api/admin/appointments?per_page=100");
|
||||
setAppointments(data.records);
|
||||
} catch (err) {
|
||||
console.error("Failed to fetch appointments:", err);
|
||||
setError("Failed to load appointments");
|
||||
|
|
|
|||
|
|
@ -445,7 +445,7 @@ export interface paths {
|
|||
};
|
||||
/**
|
||||
* Get All Appointments
|
||||
* @description Get all appointments (admin only), sorted by date descending.
|
||||
* @description Get all appointments (admin only), sorted by date descending with pagination.
|
||||
*/
|
||||
get: operations["get_all_appointments_api_admin_appointments_get"];
|
||||
put?: never;
|
||||
|
|
@ -704,6 +704,19 @@ export interface components {
|
|||
/** Revoked At */
|
||||
revoked_at: string | null;
|
||||
};
|
||||
/** PaginatedResponse[AppointmentResponse] */
|
||||
PaginatedResponse_AppointmentResponse_: {
|
||||
/** Records */
|
||||
records: components["schemas"]["AppointmentResponse"][];
|
||||
/** Total */
|
||||
total: number;
|
||||
/** Page */
|
||||
page: number;
|
||||
/** Per Page */
|
||||
per_page: number;
|
||||
/** Total Pages */
|
||||
total_pages: number;
|
||||
};
|
||||
/** PaginatedResponse[CounterRecordResponse] */
|
||||
PaginatedResponse_CounterRecordResponse_: {
|
||||
/** Records */
|
||||
|
|
@ -1617,7 +1630,10 @@ export interface operations {
|
|||
};
|
||||
get_all_appointments_api_admin_appointments_get: {
|
||||
parameters: {
|
||||
query?: never;
|
||||
query?: {
|
||||
page?: number;
|
||||
per_page?: number;
|
||||
};
|
||||
header?: never;
|
||||
path?: never;
|
||||
cookie?: never;
|
||||
|
|
@ -1630,7 +1646,16 @@ export interface operations {
|
|||
[name: string]: unknown;
|
||||
};
|
||||
content: {
|
||||
"application/json": components["schemas"]["AppointmentResponse"][];
|
||||
"application/json": components["schemas"]["PaginatedResponse_AppointmentResponse_"];
|
||||
};
|
||||
};
|
||||
/** @description Validation Error */
|
||||
422: {
|
||||
headers: {
|
||||
[name: string]: unknown;
|
||||
};
|
||||
content: {
|
||||
"application/json": components["schemas"]["HTTPValidationError"];
|
||||
};
|
||||
};
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue