AAttendrix Docsv1.0
API
ReferenceImplemented

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.

ATTENDANCE OPERATIONS INVARIANT
INV-ATT-01

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

CategoryRPC FunctionReturn TypeSecurity ContextDescription
Attendancemark_absentjsonbSECURITY DEFINERMarks an absence for a scheduled class slot.
Attendanceun_mark_absentjsonbSECURITY DEFINERRemoves an absence record, reverting state to present.
Attendancecalculate_user_attendance_v2jsonbSECURITY DEFINERRecomputes comprehensive course attendance percentages.
Attendancereset_user_attendancebooleanSECURITY DEFINERWipes logged absences for testing or fresh semester start.
Scheduleget_classes_for_datesTABLE(...)SECURITY DEFINERQueries timetable slots for given dates and user enrollments.
Scheduleschedule_classjsonbSECURITY DEFINERCreates an extra or rescheduled class slot.
Schedulereschedule_classjsonbSECURITY DEFINERUpdates timing and venue for an existing class.
Schedulecancel_classjsonbSECURITY DEFINERSoft-cancels a class slot and triggers notifications.
Schedulerestore_classbooleanSECURITY DEFINERReverts a cancelled class to scheduled active status.
Onboardingcomplete_user_onboardingjsonbSECURITY DEFINERInitializes user profile, batch, and default preferences.
Onboardingsave_course_selectionjsonbSECURITY DEFINEREnrolls user into selected elective and core courses.
Onboardingis_username_availablebooleanSECURITY DEFINERChecks if a requested username is free.
Onboardingis_roll_number_uniquebooleanSECURITY DEFINERValidates academic roll number uniqueness.
Routingget_published_routing_datasetjsonbSECURITY DEFINERFetches precomputed 152k-pair pedestrian distance matrix.
Routingrecord_walking_tripjsonbSECURITY DEFINERRecords telemetry for empirical walking speed calibration.
Devicesregister_deviceuuidSECURITY DEFINERRegisters OneSignal subscription ID and device metadata.
Devicesrefresh_device_subscriptionbooleanSECURITY DEFINERUpdates rotated OneSignal subscription identifier.
Devicesdeactivate_devicebooleanSECURITY DEFINERDeactivates 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 / PropTypeDefaultDescription
p_class_idrequired
uuidUnique identifier of the scheduled class slot from public.classes.
p_sourcerequired
textSource of the absence marking: 'student' (manual toggle) or 'system'.
p_reason
textOptional 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 specified p_class_id does 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 / PropTypeDefaultDescription
p_department_idrequired
textAcademic department identifier (e.g. 'CSE', 'ECE').
p_batch_idrequired
textBatch cohort key (e.g. 'CSE_2023').
p_roll_numberrequired
textUnique institutional roll number.
p_usernamerequired
textGlobally unique student handle.
p_full_namerequired
textFull legal or preferred name.
p_section
textClass section (e.g. 'A', 'B').
p_sub_batch
textLab group or practical sub-batch (e.g. 'B1').
p_mess_name
textEnrolled 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.

On this page