Remote Procedure Call (RPC) Reference
Authoritative specifications for PostgreSQL RPC functions invoked by the Attendrix Flutter mobile client.
Remote Procedure Call (RPC) Reference
Attendrix utilizes PostgreSQL Remote Procedure Calls (RPCs) over Supabase PostgREST to encapsulate transactional mutations, state calculations, and atomic operations. RPCs run directly inside the database engine, providing guaranteed consistency and sub-50ms execution times.
The attendance system records absences explicitly. The mark_absent RPC writes a record to public.absences; un_mark_absent removes that record. Presences are derived when no corresponding absence record exists for a valid class slot.
Overview of Client RPCs
| Category | RPC Function | Return Type | Security Context | Description |
|---|---|---|---|---|
| Attendance | mark_absent | jsonb | SECURITY DEFINER | Marks an absence for a scheduled class slot. |
| Attendance | un_mark_absent | jsonb | SECURITY DEFINER | Removes an absence record, reverting state to present. |
| Attendance | calculate_user_attendance_v2 | jsonb | SECURITY DEFINER | Recomputes comprehensive course attendance percentages. |
| Attendance | reset_user_attendance | boolean | SECURITY DEFINER | Wipes logged absences for testing or fresh semester start. |
| Schedule | get_classes_for_dates | TABLE(...) | SECURITY DEFINER | Queries timetable slots for given dates and user enrollments. |
| Schedule | schedule_class | jsonb | SECURITY DEFINER | Creates an extra or rescheduled class slot. |
| Schedule | reschedule_class | jsonb | SECURITY DEFINER | Updates timing and venue for an existing class. |
| Schedule | cancel_class | jsonb | SECURITY DEFINER | Soft-cancels a class slot and triggers notifications. |
| Schedule | restore_class | boolean | SECURITY DEFINER | Reverts a cancelled class to scheduled active status. |
| Onboarding | complete_user_onboarding | jsonb | SECURITY DEFINER | Initializes user profile, batch, and default preferences. |
| Onboarding | save_course_selection | jsonb | SECURITY DEFINER | Enrolls user into selected elective and core courses. |
| Onboarding | is_username_available | boolean | SECURITY DEFINER | Checks if a requested username is free. |
| Onboarding | is_roll_number_unique | boolean | SECURITY DEFINER | Validates academic roll number uniqueness. |
| Routing | get_published_routing_dataset | jsonb | SECURITY DEFINER | Fetches precomputed 152k-pair pedestrian distance matrix. |
| Routing | record_walking_trip | jsonb | SECURITY DEFINER | Records telemetry for empirical walking speed calibration. |
| Devices | register_device | uuid | SECURITY DEFINER | Registers OneSignal subscription ID and device metadata. |
| Devices | refresh_device_subscription | boolean | SECURITY DEFINER | Updates rotated OneSignal subscription identifier. |
| Devices | deactivate_device | boolean | SECURITY DEFINER | Deactivates subscription on logout or permission revocation. |
Attendance RPCs
mark_absent
Marks an explicit absence for a specific class slot on behalf of the calling student.
mark_absent(
p_class_id uuid,
p_source text,
p_reason text DEFAULT NULL
) RETURNS jsonb- Security:
SECURITY DEFINER - Permission: Authenticated user (
auth.uid())
Parameters
| Field / Prop | Type | Default | Description |
|---|---|---|---|
p_class_idrequired | uuid | — | Unique identifier of the scheduled class slot from public.classes. |
p_sourcerequired | text | — | Source of the absence marking: 'student' (manual toggle) or 'system'. |
p_reason | text | — | Optional human-readable explanation (e.g. 'Medical Leave', 'Club Event'). |
Response Schema
{
"success": true,
"is_absent": true,
"class_id": "00000000-0000-0000-0000-000000000001",
"user_id": "00000000-0000-0000-0000-000000000002",
"timestamp": "2026-09-04T10:15:00.000Z",
"course_id": "CS301",
"attendance": {
"attended": 24,
"missed": 3,
"percentage": 88.89,
"required": 80
}
}Error Codes
CLASS_NOT_FOUND: The specifiedp_class_iddoes not exist.CLASS_CANCELLED: Cannot mark absence for a cancelled class slot.ALREADY_MARKED: Absence record already exists for this student and class.
un_mark_absent
Removes a previously logged absence, reverting the student's status for that class slot to present.
un_mark_absent(
p_class_id uuid
) RETURNS jsonb- Security:
SECURITY DEFINER - Permission: Authenticated user (
auth.uid())
Response Schema
{
"success": true,
"is_absent": false,
"class_id": "00000000-0000-0000-0000-000000000001",
"user_id": "00000000-0000-0000-0000-000000000002",
"timestamp": "2026-09-04T10:20:00.000Z",
"course_id": "CS301",
"attendance": {
"attended": 25,
"missed": 2,
"percentage": 92.59,
"required": 80
}
}Timetable & Schedule RPCs
get_classes_for_dates
Retrieves all scheduled, rescheduled, and extra classes for an array of calendar dates, joining course metadata and absence indicators.
get_classes_for_dates(
p_dates text[]
) RETURNS TABLE(
class_id uuid,
course_id text,
course_code text,
course_name text,
batch_id text,
scheduled_start timestamptz,
scheduled_end timestamptz,
venue text,
is_cancelled boolean,
is_extra_class boolean,
is_plus_slot boolean,
is_absent boolean
)- Security:
SECURITY DEFINER - Permission: Authenticated user
Onboarding & Enrollment RPCs
complete_user_onboarding
Initializes student profile details, assigns academic department and batch, and sets up default user preferences within a single atomic database transaction.
complete_user_onboarding(
p_department_id text,
p_batch_id text,
p_roll_number text,
p_username text,
p_full_name text,
p_section text,
p_sub_batch text,
p_mess_name text
) RETURNS jsonb| Field / Prop | Type | Default | Description |
|---|---|---|---|
p_department_idrequired | text | — | Academic department identifier (e.g. 'CSE', 'ECE'). |
p_batch_idrequired | text | — | Batch cohort key (e.g. 'CSE_2023'). |
p_roll_numberrequired | text | — | Unique institutional roll number. |
p_usernamerequired | text | — | Globally unique student handle. |
p_full_namerequired | text | — | Full legal or preferred name. |
p_section | text | — | Class section (e.g. 'A', 'B'). |
p_sub_batch | text | — | Lab group or practical sub-batch (e.g. 'B1'). |
p_mess_name | text | — | Enrolled dining facility name for meal alerts. |
Routing & Navigation RPCs
get_published_routing_dataset
Streams the latest published offline pedestrian routing dataset to the mobile client for in-memory caching.
get_published_routing_dataset() RETURNS jsonb- Security:
SECURITY DEFINER - Response Size: Approximately 15.3 MB of precomputed shortest-path route records across 152,904 origin-destination pairs.
- Client Cache Strategy: Downloaded once upon bootstrap; stored locally in SQLite / shared preferences with cache invalidation triggered only by a version bump in
routing_dataset_versions.
Was this page helpful?
Your feedback directly guides the engineering documentation roadmap.