Spaces:
Sleeping
Sleeping
File size: 13,627 Bytes
b4c4de1 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 | # EduVerse API - Courses & Enrollments Documentation for Flutter
This document provides comprehensive details on the `Courses` and `Enrollments` endpoints. It is formatted to aid your Flutter application integration, containing the expected request shapes, query parameters, response structures, and sample Dart definitions for your state management and models.
---
## 1. General Info & Headers
**Base URL**
- **Local Dev**: `http://localhost:8081` (or `http://10.0.2.2:8081` for Android Emulators)
- **Production**: `<PRODUCTION_URL>`
**Headers**
Many of these endpoints require an active session. Pass the JWT `accessToken` in the header:
```text
Authorization: Bearer <accessToken>
```
---
## 2. General Course Browsing (Public / Discovery)
These endpoints do NOT require an authentication token. They are used for the course catalog.
### 2.1 List All Courses
**Endpoint:** `GET /api/courses`
**Access:** Public
**Description:** Retrieves a paginated list of all courses in the catalog.
**Query Parameters:**
- `departmentId` (int, optional): Filter by department.
- `level` (string, optional): Filter by course level (e.g. "100", "300").
- `status` (string, optional): Filter by status (`active`, `inactive`).
- `search` (string, optional): Search by name or code.
- `page` (int, optional): Default: 1.
- `limit` (int, optional): Default: 20.
**Success Response (HTTP 200)**
```json
{
"data": [
{
"id": 1,
"code": "CS101",
"name": "Introduction to Computer Science",
"credits": 3,
"level": "100",
"departmentId": 1,
"status": "active"
}
],
"total": 50,
"page": 1,
"limit": 20,
"totalPages": 3
}
```
### 2.2 Get Course Details
**Endpoint:** `GET /api/courses/:id`
**Access:** Public
**Description:** Detailed info for a specific course, including section counts and prerequisites.
**Success Response (HTTP 200)**
```json
{
"id": 1,
"code": "CS101",
"name": "Intro to CS",
"description": "Basics of OOP...",
"credits": 3,
"prerequisitesCount": 0,
"sectionsCount": 2,
"status": "active"
}
```
---
## 3. Student Enrollment Flow
These endpoints are specifically designated for students to manage their schedules.
### 3.1 Get Available Courses
**Endpoint:** `GET /api/enrollments/available`
**Access:** Protected (`Bearer Token`, Role: STUDENT)
**Description:** Lists courses that the current student is eligible to enroll in (prerequisites met, sections available).
**Query Parameters:**
- `departmentId` (int)
- `semesterId` (int)
- `search` (string)
- `level` (string)
- `page` (int, default 1)
- `limit` (int, default 20)
**Success Response (HTTP 200)**
*Note: This specific shape is critical for your "Add Course" screen.*
```json
[
{
"id": 10,
"name": "Data Structures",
"code": "CS201",
"description": "...",
"credits": 4,
"level": "200",
"departmentId": 1,
"departmentName": "Computer Science",
"sections": [
{
"id": 5,
"sectionNumber": "01",
"maxCapacity": 50,
"currentEnrollment": 45,
"availableSeats": 5,
"location": "Room 204",
"semesterId": 1,
"semesterName": "Fall 2026"
}
],
"prerequisites": [],
"canEnroll": true,
"enrollmentStatus": null
}
]
```
### 3.2 Enroll in a Section
**Endpoint:** `POST /api/enrollments/register`
**Access:** Protected (`Bearer Token`, Role: STUDENT)
**Description:** Enrolls the student in a specific course section.
**Request Body (`EnrollCourseDto`)**
```json
{
"sectionId": 5 // Required: The ID of the specific section to enroll in
}
```
**Success Response (HTTP 201 Created)**
Returns the full Enrollment Response.
```json
{
"id": 150,
"userId": 42,
"sectionId": 5,
"status": "enrolled",
"enrollmentDate": "2026-08-15T10:00:00.000Z"
}
```
**Error Responses:**
- **400 Bad Request**: Prerequisites not met, or a schedule conflict exists.
- **409 Conflict**: Already enrolled in this course.
### 3.3 Get My Enrolled Courses
**Endpoint:** `GET /api/enrollments/my-courses`
**Access:** Protected (`Bearer Token`, Role: STUDENT)
**Description:** Retrieves all active and past enrollments for the student.
**Query Parameters:**
- `semester` (int, optional): Filter by semester ID.
**Success Response (HTTP 200)**
Returns an array of Enrollment objects.
```json
[
{
"id": 150,
"userId": 42,
"sectionId": 5,
"status": "enrolled",
"grade": null,
"finalScore": null,
"enrollmentDate": "2026-08-15T10:00:00.000Z",
"canDrop": true,
"dropDeadline": "2026-09-01T23:59:59.000Z",
"course": {
"id": 10,
"name": "Data Structures",
"code": "CS201",
"description": "...",
"credits": 4,
"level": "200"
},
"section": {
"id": 5,
"sectionNumber": "01",
"maxCapacity": 50,
"currentEnrollment": 46,
"location": "Room 204"
},
"semester": {
"id": 1,
"name": "Fall 2026",
"startDate": "2026-08-20T00:00:00.000Z",
"endDate": "2026-12-15T00:00:00.000Z"
}
}
]
```
### 3.4 Drop Course
**Endpoint:** `DELETE /api/enrollments/:id`
**Access:** Protected (`Bearer Token`, Role: STUDENT or ADMIN)
**Description:** Withdraws from an enrolled course. Uses the `enrollmentId`, NOT the `courseId`.
**Request Shape**
*Note: Endpoint is DELETE, no request body typically needed for simple drops, but dropReason might be an optional body in the backend.*
**Success Response (HTTP 200 / HTTP 204)**
- **400 Bad Request**: The drop deadline for the semester has passed.
---
## 4. Instructor & TA Flow
### 4.1 Get Teaching Courses
**Endpoint:** `GET /api/enrollments/teaching`
**Access:** Protected (`Bearer Token`, Role: INSTRUCTOR, TA)
**Description:** Retrieves sections assigned to the current instructor or teaching assistant (TA).
**Payload Structure (Option C Answer):**
This endpoint returns a **completely different shape** (Option C) from the student's `my-courses`. It does not include student-specific fields like `status`, `grade`, or `dropDeadline`. Instead, it provides a streamlined model mapping the instructor/TA directly to the courses and sections they teach or assist.
**Success Response (HTTP 200)**
```json
[
{
"sectionId": 5,
"courseId": 10,
"course": {
"id": 10,
"name": "Data Structures",
"code": "CS201",
"description": "...",
"credits": 4,
"level": "200"
},
"section": {
"id": 5,
"sectionNumber": "01",
"maxCapacity": 50,
"currentEnrollment": 46,
"location": "Room 204"
},
"semester": {
"id": 1,
"name": "Fall 2026",
"startDate": "2026-08-20T00:00:00.000Z",
"endDate": "2026-12-15T00:00:00.000Z"
}
}
]
```
### 4.2 Get Section TAs
**Endpoint:** `GET /api/enrollments/sections/:sectionId/tas`
**Access:** Protected (`Bearer Token`, Role: INSTRUCTOR, ADMIN)
**Description:** Returns a detailed list of all Teaching Assistants assigned to a course section. Useful for instructors managing their assigned courses. Note: The Instructor flow uses this to view who is helping teach the course.
**Success Response (HTTP 200)**
```json
[
{
"id": 1,
"sectionId": 10,
"userId": 7,
"responsibilities": "Grading assignments",
"assignedAt": "2026-08-15T10:00:00.000Z",
"firstName": "Jane",
"lastName": "Smith",
"email": "jane.smith@example.com"
}
]
```
### 4.3 TA Specific Notes for Flutter
- **Reusability**: You can heavily reuse the `TeachingCourseModel` for both Instructor and TA dashboards, as the `/api/enrollments/teaching` endpoint acts as the primary data source for both roles and yields identical structural responses.
- **Permissions Limitation**: TAs generally have view access to the sections they assist with, but unlike Administrators or Instructors, they do not automatically have elevated endpoints for managing enrollments (like dropping other students or viewing the waitlist from this API controller) unless additionally scoped. Keep the TA UI strictly focused on Course views and other authorized tools (e.g., grading, forums).
---
## Flutter & Dart Implementation Tips
### 1. Data Models (Using `freezed`)
Having a unified model for the complex enrollment response handles your main dashboard rendering efficiently:
```dart
import 'package:freezed_annotation/freezed_annotation.dart';
part 'enrollment_model.freezed.dart';
part 'enrollment_model.g.dart';
@freezed
class EnrollmentModel with _$EnrollmentModel {
const factory EnrollmentModel({
required int id,
required int userId,
required int sectionId,
required String status, // 'enrolled', 'waitlisted', 'dropped', 'completed', 'failed'
String? grade,
double? finalScore,
required DateTime enrollmentDate,
DateTime? droppedAt,
DateTime? completedAt,
@Default(false) bool canDrop,
DateTime? dropDeadline,
// Nested relationships mapping
CourseSummaryModel? course,
SectionSummaryModel? section,
SemesterSummaryModel? semester,
}) = _EnrollmentModel;
factory EnrollmentModel.fromJson(Map<String, dynamic> json) => _$EnrollmentModelFromJson(json);
}
@freezed
class CourseSummaryModel with _$CourseSummaryModel {
const factory CourseSummaryModel({
required int id,
required String name,
required String code,
required String description,
required int credits,
required String level,
}) = _CourseSummaryModel;
factory CourseSummaryModel.fromJson(Map<String, dynamic> json) => _$CourseSummaryModelFromJson(json);
}
@freezed
class SectionSummaryModel with _$SectionSummaryModel {
const factory SectionSummaryModel({
required int id,
required String sectionNumber,
required int maxCapacity,
required int currentEnrollment,
String? location,
}) = _SectionSummaryModel;
factory SectionSummaryModel.fromJson(Map<String, dynamic> json) => _$SectionSummaryModelFromJson(json);
}
@freezed
class SemesterSummaryModel with _$SemesterSummaryModel {
const factory SemesterSummaryModel({
required int id,
required String name,
required DateTime startDate,
required DateTime endDate,
}) = _SemesterSummaryModel;
factory SemesterSummaryModel.fromJson(Map<String, dynamic> json) => _$SemesterSummaryModelFromJson(json);
}
@freezed
class TeachingCourseModel with _$TeachingCourseModel {
const factory TeachingCourseModel({
required int sectionId,
required int courseId,
required CourseSummaryModel course,
required SectionSummaryModel section,
required SemesterSummaryModel semester,
}) = _TeachingCourseModel;
factory TeachingCourseModel.fromJson(Map<String, dynamic> json) => _$TeachingCourseModelFromJson(json);
}
@freezed
class TAAssignmentModel with _$TAAssignmentModel {
const factory TAAssignmentModel({
required int id,
required int sectionId,
required int userId,
String? responsibilities,
required DateTime assignedAt,
required String firstName,
required String lastName,
required String email,
}) = _TAAssignmentModel;
factory TAAssignmentModel.fromJson(Map<String, dynamic> json) => _$TAAssignmentModelFromJson(json);
}
```
### 2. Available Courses Data Flow (Search Screen)
When rendering the "Browse Courses" view, map to the `AvailableCoursesDto` structure:
```dart
@freezed
class AvailableCourseModel with _$AvailableCourseModel {
const factory AvailableCourseModel({
required int id,
required String name,
required String code,
required String description,
required int credits,
required String level,
required int departmentId,
required String departmentName,
@Default([]) List<AvailableSectionModel> sections,
required bool canEnroll,
String? enrollmentStatus,
}) = _AvailableCourseModel;
factory AvailableCourseModel.fromJson(Map<String, dynamic> json) => _$AvailableCourseModelFromJson(json);
}
@freezed
class AvailableSectionModel with _$AvailableSectionModel {
const factory AvailableSectionModel({
required int id,
required String sectionNumber,
required int maxCapacity,
required int currentEnrollment,
required int availableSeats,
String? location,
required int semesterId,
required String semesterName,
}) = _AvailableSectionModel;
factory AvailableSectionModel.fromJson(Map<String, dynamic> json) => _$AvailableSectionModelFromJson(json);
}
```
### 3. API Service (using `Dio`)
Example API calls using Dio:
```dart
class EnrollmentApi {
final Dio _dio;
EnrollmentApi(this._dio);
Future<List<EnrollmentModel>> getMyCourses({int? semesterId}) async {
final response = await _dio.get('/api/enrollments/my-courses', queryParameters: {
if (semesterId != null) 'semester': semesterId,
});
return (response.data as List).map((json) => EnrollmentModel.fromJson(json)).toList();
}
Future<EnrollmentModel> enrollInSection(int sectionId) async {
final response = await _dio.post('/api/enrollments/register', data: {
'sectionId': sectionId,
});
return EnrollmentModel.fromJson(response.data);
}
Future<List<TeachingCourseModel>> getTeachingCourses() async {
final response = await _dio.get('/api/enrollments/teaching');
return (response.data as List).map((json) => TeachingCourseModel.fromJson(json)).toList();
}
Future<List<TAAssignmentModel>> getSectionTAs(int sectionId) async {
final response = await _dio.get('/api/enrollments/sections/$sectionId/tas');
return (response.data as List).map((json) => TAAssignmentModel.fromJson(json)).toList();
}
}
```
|