๐ŸŽ“ Sapelaweddo API

Complete REST API for Learning Management System

v1.0.0 Firebase Express.js

๐Ÿ” Authentication

All protected endpoints require a Firebase ID token in the Authorization header:

Authorization: Bearer YOUR_FIREBASE_ID_TOKEN

Get your token from Firebase Authentication after login.

๐Ÿ“š Base URL

http://api.dubhub.lk/api

๐Ÿ‘ค Authentication Endpoints

POST /api/auth/verify
Verify Firebase ID token and get user info
Request Body: { "idToken": "your_firebase_id_token" }

๐ŸŽ“ Student Endpoints

GET /api/students ๐Ÿ”’ Auth ๐Ÿ‘‘ Admin
Get all students (admin only)
Query Parameters: ?examYear=2025&limit=50&offset=0
GET /api/students/:id ๐Ÿ”’ Auth
Get student by ID (own profile or admin)
POST /api/students ๐Ÿ”’ Auth
Create new student profile
Request Body: { "firstName": "John", "lastName": "Doe", "email": "john@example.com", "phoneNumber": "0771234567", "examYear": "2025", "schoolName": "Example School", ... }
PUT /api/students/:id ๐Ÿ”’ Auth
Update student profile (own profile or admin)
DELETE /api/students/:id ๐Ÿ”’ Auth ๐Ÿ‘‘ Admin
Delete student (admin only)

๐Ÿ“ข Notice Endpoints

GET /api/notices ๐Ÿ”’ Auth
Get all notices (filtered by target audience)
Query Parameters: ?targetYear=2025&limit=20
GET /api/notices/:id ๐Ÿ”’ Auth
Get notice by ID
POST /api/notices ๐Ÿ”’ Auth ๐Ÿ‘‘ Admin
Create new notice (admin only)
Request Body: { "title": "Important Notice", "message": "Notice content here", "imageUrl": "https://...", "targetAudience": "2025" }
DELETE /api/notices/:id ๐Ÿ”’ Auth ๐Ÿ‘‘ Admin
Delete notice (admin only)

๐Ÿ“– Class Endpoints

GET /api/classes ๐Ÿ”’ Auth
Get all accessible classes
Query Parameters: ?targetYear=2025&accessType=lifetime
GET /api/classes/:id ๐Ÿ”’ Auth
Get class by ID (if user has access)
POST /api/classes ๐Ÿ”’ Auth ๐Ÿ‘‘ Admin
Create new class (admin only)
Request Body: { "title": "Mathematics Class", "description": "Advanced algebra", "youtubeLink": "https://youtube.com/...", "targetYear": "2025", "accessType": "lifetime" }
DELETE /api/classes/:id ๐Ÿ”’ Auth ๐Ÿ‘‘ Admin
Delete class (admin only)

๐Ÿ† Exam Endpoints

GET /api/exams ๐Ÿ”’ Auth
Get all live exams
Query Parameters: ?targetYear=2025&status=active
GET /api/exams/:id ๐Ÿ”’ Auth
Get exam by ID
POST /api/exams ๐Ÿ”’ Auth ๐Ÿ‘‘ Admin
Create new exam (admin only)
DELETE /api/exams/:id ๐Ÿ”’ Auth ๐Ÿ‘‘ Admin
Delete exam (admin only)

๐Ÿ“„ Paper Endpoints

GET /api/papers ๐Ÿ”’ Auth
Get all papers (notes, past papers, model papers)
Query Parameters: ?type=note&targetYear=2025&subject=Mathematics
POST /api/papers ๐Ÿ”’ Auth ๐Ÿ‘‘ Admin
Create new paper (admin only)

๐Ÿ“ Submission Endpoints

GET /api/submissions ๐Ÿ”’ Auth
Get exam submissions (own submissions or all if admin)
POST /api/submissions ๐Ÿ”’ Auth
Submit exam answers
Request Body: { "examId": "exam123", "answers": [...], "score": 85, "totalPoints": 100 }
PUT /api/submissions/:id/mark ๐Ÿ”’ Auth ๐Ÿ‘‘ Admin
Mark writing answers (admin only)

โฐ Work Time Endpoints

GET /api/worktime/:userId ๐Ÿ”’ Auth
Get work time records for user
Query Parameters: ?startDate=2024-01-01&endDate=2024-01-31
POST /api/worktime ๐Ÿ”’ Auth
Record daily work time
Request Body: { "hours": 9, "date": "2024-01-15" }

๐Ÿ“Š Response Format

Success Response:

{ "success": true, "data": { ... }, "message": "Operation successful" }

Error Response:

{ "error": "Error Type", "message": "Detailed error message" }

๐Ÿš€ Quick Start

1. Get Firebase ID Token:

// After Firebase Authentication const idToken = await user.getIdToken();

2. Make API Request:

fetch('http://api.dubhub.lk/api/students', { method: 'GET', headers: { 'Authorization': 'Bearer ' + idToken, 'Content-Type': 'application/json' } }) .then(res => res.json()) .then(data => console.log(data));