0% found this document useful (0 votes)
11 views6 pages

Classroom Management API

The Classroom Management API provides models for roles, users, and classrooms, with defined relationships and access control levels. It includes various endpoints for user authentication, classroom management, and enrollment processes, each with specific authentication requirements and error handling. The API supports operations such as listing, adding, updating, and deleting classrooms, as well as enrolling students and assigning teachers.

Uploaded by

024Pritesh Kadam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views6 pages

Classroom Management API

The Classroom Management API provides models for roles, users, and classrooms, with defined relationships and access control levels. It includes various endpoints for user authentication, classroom management, and enrollment processes, each with specific authentication requirements and error handling. The API supports operations such as listing, adding, updating, and deleting classrooms, as well as enrolling students and assigning teachers.

Uploaded by

024Pritesh Kadam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

📘 Classroom Management API

Models:

🧩 Role Model:
Field Name Data Type Primary Key Foreign Key Comments
id Integer Yes
roleName String Unique
users List Related with
user table

👤 User Model:
Field Name Data Type Primary Key Foreign Key Comments
id Integer Yes
username String
email String Unique
password String
roleObj Object Yes One-to-Many
with Role
Model
classrooms List Related with
classroom table

🏫 Classroom Model:
Field Name Data Type Primary Key Foreign Key Comments
id Integer Yes
classCode String Unique
subject String
createdAt Date Default = Today
isArchived Boolean Default = False
teacherComme String Optional
nts
classStatus String Default =
"Active"
teacherObj Object Yes One-to-Many
with User
Model

🔐 Role List:
ID | Role Name
---|-----------
1 | Admin
2 | Teacher
3 | Student
👥 Sample Users:
ID | Username | Email | Password | Role ID
---|----------|-------|----------|---------
1 | anita | [email protected] | pass123 | 1
2 | ravi | [email protected] | pass456 | 2
3 | sneha | [email protected] | pass789 | 3

🚦 Access Control:
🟢 Public: No authentication required
🟠 Authenticated: Any logged-in user
🔵 Admin-only: Must be authenticated with role “admin”
🔴 Teacher-only: Must be authenticated with role “teacher”

Endpoints:

user/login/
**Method**: POST
**Authentication**: None
**Description**: Authenticate using email and password. Returns token on success.

Request:

{
"email": "[email protected]",
"password": "pass456"
}

Response:

{
"username": "ravi",
"token": "someauthtoken"
}

Errors:

 - Invalid credentials → "Invalid email or password" (400)

classroom/list/
**Method**: GET
**Authentication**: 🟠 Authenticated
**Description**: Return all classrooms for a teacher. Requires classCode as a query
parameter.

Request:

localhost:8000/classroom/list/?classCode=CS101
Response:

List of classroom objects with that classCode.

Errors:

 - No query param → "classCode is required" (400)

classroom/add/
**Method**: POST
**Authentication**: 🔴 Teacher-only
**Description**: Creates a new classroom.

Request:

{
"classCode": "CS101",
"subject": "Computer Science",
"teacherComments": "First year class"
}

Response:

{
"id": 4,
"teacherObj": 2,
"classCode": "CS101",
"subject": "Computer Science",
"createdAt": "2025-05-04",
"isArchived": false,
"teacherComments": "First year class",
"classStatus": "Active"
}

Errors:

 - classCode exists → "Class code already exists" (400)


 - User not a teacher → "You don’t have permission to perform this operation" (403)

classroom/update/<int:id>/
**Method**: PATCH
**Authentication**: 🔵 Admin-only
**Description**: Updates the classStatus (e.g., 'Archived').

Request:

{
"classStatus": "Archived"
}

Response:
Returns updated classroom object.

Errors:

 - ID not found → "Classroom not found" (404)


 - No data → "No update data provided" (400)
 - Not admin → "You don’t have permission to perform this operation" (403)

classroom/delete/<int:id>/
**Method**: DELETE
**Authentication**: 🔴 Teacher-only
**Description**: Delete a classroom. Only the teacher who created it can delete.

Response:

Status code 204

Errors:

 - ID not found → "Classroom not found" (404)


 - Not creator → "You don’t have permission to perform this operation" (403)

classroom/enroll/
**Method**: POST
**Authentication**: 🟠 Authenticated
**Description**: Enroll a student into a classroom.

Request:

{
"classCode": "CS101"
}

Response:

{
"message": "Student enrolled successfully"
}

Errors:

 - Not a student → "Only students can enroll" (403)


 - Class not found → "Classroom not found" (404)
 - Already enrolled → "Student already enrolled" (400)

classroom/students/<str:classCode>/
**Method**: GET
**Authentication**: 🔴 Teacher-only
**Description**: Lists all students enrolled in a classroom.
Response:

[
{
"id": 3,
"username": "sneha",
"email": "[email protected]"
}
]

Errors:

 - Not the teacher → "Access denied" (403)


 - Class not found → "Classroom not found" (404)

classroom/assign-teacher/
**Method**: PATCH
**Authentication**: 🔵 Admin-only
**Description**: Allows an admin to reassign a classroom to a new teacher.

Request:

{
"classCode": "CS101",
"newTeacherId": 5
}

Response:

{
"message": "Teacher reassigned successfully"
}

Errors:

 - Not admin → "Only admins can assign teachers" (403)


 - Invalid teacher ID → "Invalid teacher ID" (404)

classroom/catalog/
**Method**: GET
**Authentication**: 🟢 Public
**Description**: Publicly viewable list of all active classrooms.

Response:

[
{
"classCode": "CS101",
"subject": "Computer Science",
"teacher": "ravi"
}
]

classroom/my-enrollments/
**Method**: GET
**Authentication**: 🟠 Authenticated
**Description**: Shows all classrooms a logged-in student is enrolled in.

Response:

[
{
"classCode": "CS101",
"subject": "Computer Science",
"classStatus": "Active"
}
]

Errors:

 - Not a student → "Only students can view enrollments" (403)

You might also like