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:
counterweight 2025-12-21 17:32:25 +01:00
parent 1cd60b4bbc
commit 77e7f98e1e
Signed by: counterweight
GPG key ID: 883EDBAA726BD96C
4 changed files with 70 additions and 28 deletions

View file

@ -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");