The Student and Course Management API is a RESTful API built using NestJS for managing student resources, including their personal information and the courses they have taken each year. The API uses an SQL database with MySQL to store student and course data and provides various endpoints to perform operations on students and courses.
- SOLID Principles: The project follows the SOLID principles, ensuring that the codebase is modular, maintainable, and scalable.
- DRY (Don't Repeat Yourself): The codebase emphasizes the DRY principle by minimizing code duplication. Reusable components and services are employed to avoid redundancy and maintain code consistency.
- Data Validation: Data validation is implemented at multiple levels of the application to ensure data integrity and security. Input validation is performed on the server-side to prevent invalid data from being processed.
- GET /students: Retrieve a list of all students' personal information, including courses they have taken. You can also filter students by year. (OPTIONAL)
- GET /students/:student_id: Retrieve specific student's personal information and courses they have taken. You can also filter by year. (OPTIONAL)
- POST /students: Create a new student.
- PUT /students/:student_id: Update a student's personal information.
- DELETE /students/:student_id: Delete a student and all related course records.
- GET /courses: Retrieve a list of all courses.
- GET /courses/:course_name: Retrieve information about a specific course.
- POST /courses: Create a new course for students
- POST /courses/assign/:course_name: Assign a student or students to a specific course
- PUT /courses/:course_name: Update course information.
- PUT /courses/unassign/:course_name: Unassign a student or students from a specific course
- DELETE /courses/:course_name: Delete a course.
Here are the main API endpoints with examples of how to use them:
Retrieve all students with courses for all years or for a specific year:
Retrieve a specific student with courses for all years or for a specific year:
Create a new student:
Update a student's information:
Delete a student also his related course records:
Retrieve a list of all courses:
Retrieve information about a specific course:
Create a new course for a student:
Assign students to a course:
Update course information:
Unassign students from course
Delete a course and also the records of students assigned to it:
GET /students (For all years)
GET /students?year=<year> (OPTIONAL, specific year)
GET /students/:student_id (For all years)
GET /students/:student_id?year=<year> (OPTIONAL, specific year)
POST /students
Example request body:
{
"firstname": "John",
"lastname": "Doe",
"address": "123 Main St"
}
PUT /students/:student_id
Example request body:
{
"firstname": "Updated First Name",
"lastname": "Updated Last Name",
"address": "Updated Address"
}
DELETE /students/:student_id
GET /courses
GET /courses/:course_name
POST /courses
Example request body:
{
"course_name": "Mathematics",
"year": 2023
}
POST /courses/assign/:course_name
Example request body:
{
"studentIds": [1 ,2], // number:[] , array of numbers
}
PUT /courses/:course_name
Example request body:
{
"course_name": "Updated Course Name",
"year": 2024
}
PUT /courses/unassign/:course_name
Example request body:
{
"studentsIds": [4], // This is an array of numbers
}
DELETE /courses/:course_name
Please make sure you have the following installed:
- Docker Desktop to run the container of MySQL DB
- Node JS ver 18+
- MySQL Workbench, DBeaver etc.. for viewing the DB in real-time
- Postman, Insomnia etc.. for API Testing
To run this project locally, follow these steps:
- Clone the repository from Github:
- Navigate to the project directory:
cd your-repository
docker-compose up --build
After running the migration the tables are generated and will be visible at MySQL WorkBench
The API should now be running locally and accessible at http://localhost:3000.
You may test the API with Postman, Insomnia and look at the changes at real time with MySQL Workbench or any other application