API Documentation | Code Documentation
This project is an API for managing online courses, with functionalities for teachers and students.
To run the project locally, follow these steps:
- Clone the repository from the master branch.
https://github.com/Walttinho/lms.git - Navigate to the project directory.
cd lms - Install dependencies using npm or yarn:
npm installoryarn install. - Set up your environment variables as needed.
touch .env && echo -e "DATABASE_URL=\nPORT=\nJWT_SECRET=" >> .env - Run the application:
npm run start:devoryarn start:dev.
To run the project using Docker, follow these steps:
- Install Docker on your machine if you haven't already.
- Build the Docker image:
docker build -t lms-backend . - Run the Docker container:
docker run -p 3000:3000 lms-backend
To apply database migrations and seeding, follow these steps:
- Run database migrations:
prisma migrate dev - Seed the database with initial data:
prisma db seed
- Administrator Access: Use the appropriate token in the request header to simulate administrator access.
- Professor Access: Use the appropriate token in the request header to simulate professor access.
- Student Access: Use the appropriate token in the request header to simulate student access.
For detailed information on each endpoint, click on the endpoint name. Additionally, you can visit the interactive documentation at Swagger to explore and test the API endpoints directly in your browser.
- POST /user: Create a new user.
- GET /user/all: List all users.
- GET /user: Find a user by ID.
- DELETE /user/:id: Delete a user by ID.
- PATCH /user: Update a user.
- POST /auth: User login.
- POST /courses: Create a new course.
- POST /courses/:courseId/lessons: Create a new lesson for a specific course.
- GET /courses: List all courses.
- GET /courses/:courseId/lessons: List all lessons for a specific course.
- GET /courses/:id: Find a course by ID.
- GET /courses/:courseId/lessons/:id: Find a lesson by ID for a specific course update watching lesson for Students.
- PUT /courses/:id: Update a course by ID.
- PUT /courses/:courseId/lessons/:id: Update a lesson by ID for a specific course.
- DELETE /courses/:id: Delete a course by ID.
- DELETE /courses/:courseId/lessons/:id: Delete a lesson by ID for a specific course.
We appreciate all contributors who have helped make this project what it is today. If you are interested in contributing, please follow the instructions below:
- Fork the project.
- Create a branch with the name of your feature or fix (
git checkout -b feature/my-new-feature). - Make your changes and commit them (
git commit -am 'Add some feature'). - Push to your branch (
git push origin feature/my-new-feature). - Open a Pull Request.
Please ensure your code is in line with the project's style guidelines and that all test checks are passing.
Nest is MIT licensed.
Route: POST /user
Description: Creates a new user.
Request Body:
{
"name": "John Doe",
"username": "johndoe",
"email": "john.doe@example.com",
"password": "SecurePassword123!",
"role": "STUDENTS"
}Response:
{
"id": "123e4567-e89b-12d3-a456-42661417400",
"name": "John Doe",
"username": "johndoe",
"email": "john.doe@example.com",
"role": "STUDENTS"
}Route: GET /user/all
Description: Lists all users available.
Response:
[
{
"id": "123e4567-e89b-12d3-a456-42661417400",
"name": "John Doe",
"username": "johndoe",
"email": "john.doe@example.com",
"role": "STUDENTS"
},
{
"id": "123e4567-e89b-12d3-a456-42661417401",
"name": "Jane Smith",
"username": "janesmith",
"email": "jane.smith@example.com",
"role": "PROFESSOR"
}
]Route: GET /user
Description: Finds a user by ID.
Response:
{
"id": "123e4567-e89b-12d3-a456-42661417400",
"name": "John Doe",
"username": "johndoe",
"email": "john.doe@example.com",
"role": "STUDENTS"
}Route: DELETE /user/:id
Description: Deletes a user by ID.
Response:
{
"message": "User deleted successfully"
}Route: PATCH /user
Description: Updates a user.
Request Body:
{
"name": "Johnathan Doe",
"username": "johnathandoe",
"email": "johnathan.doe@example.com",
"password": "NewSecurePassword123!",
"role": "ADMINISTRATOR"
}Response:
{
"id": "123e4567-e89b-12d3-a456-42661417400",
"name": "Johnathan Doe",
"username": "johnathandoe",
"email": "johnathan.doe@example.com",
"role": "ADMINISTRATOR"
}6. User Login
Route: POST /auth
Description: Logs in a user.
Request Body:
{
"email": "johnathan.doe@example.com",
"username": "johnathandoe",
"password": "NewSecurePassword123!"
}Response:
{
"user": {
"id": "123e4567-e89b-12d3-a456-42661417400",
"name": "Johnathan Doe",
"username": "johnathandoe",
"email": "johnathan.doe@example.com"
},
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3OCwidXNlcm5hbWUiOiJqb2huYWRvbm9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c"
}Route: POST /courses
Description: Creates a new course.
Request Body:
{
"name": "Introduction to Programming",
"description": "Learn the basics of programming.",
"banner": "https://example.com/images/programming.jpg"
}Response:
{
"id": "123e4567-e89b-12d3-a456-42661417402",
"name": "Introduction to Programming",
"description": "Learn the basics of programming.",
"banner": "https://example.com/images/programming.jpg",
"createdAt": "2023-04-01T00:00:00Z",
"updatedAt": "2023-04-01T00:00:00Z"
}Route: POST /courses/:courseId/lessons
Description: Creates a new lesson for a specific course.
Request Body:
{
"name": "Getting Started with Python",
"description": "Learn how to write your first Python program.",
"content": "In this lesson, you will learn how to write a simple Python program.",
"role": "TEXT",
"courseId": "123e4567-e89b-12d3-a456-42661417402"
}Response:
{
"id": "123e4567-e89b-12d3-a456-42661417403",
"name": "Getting Started with Python",
"description": "Learn how to write your first Python program.",
"content": "In this lesson, you will learn how to write a simple Python program.",
"role": "TEXT",
"courseId": "123e4567-e89b-12d3-a456-42661417402"
}Route: GET /courses
Description: Lists all courses available.
Query Parameters:
page: Page number (optional, default 1)size: Number of items per page (optional, default 10)
Response:
[
{
"id": "123e4567-e89b-12d3-a456-42661417402",
"name": "Introduction to Programming",
"description": "Learn the basics of programming.",
"banner": "https://example.com/images/programming.jpg",
"createdAt": "2023-04-01T00:00:00Z",
"updatedAt": "2023-04-01T00:00:00Z"
},
{
"id": "123e4567-e89b-12d3-a456-42661417404",
"name": "Advanced Python Programming",
"description": "Dive deeper into Python programming.",
"banner": "https://example.com/images/advanced-python.jpg",
"createdAt": "2023-04-02T00:00:00Z",
"updatedAt": "2023-04-02T00:00:00Z"
}
]Route: GET /courses/:courseId/lessons
Description: Lists all lessons for a specific course.
Query Parameters:
page: Page number (optional, default 1)size: Number of items per page (optional, default 10)
Response:
[
{
"id": "123e4567-e89b-12d3-a456-42661417403",
"name": "Getting Started with Python",
"description": "Learn how to write your first Python program.",
"content": "In this lesson, you will learn how to write a simple Python program.",
"role": "TEXT",
"courseId": "123e4567-e89b-12d3-a456-42661417402"
},
{
"id": "123e4567-e89b-12d3-a456-42661417405",
"name": "Variables and Data Types",
"description": "Understand variables and data types in Python.",
"content": "In this lesson, you will learn about variables and data types in Python.",
"role": "TEXT",
"courseId": "123e4567-e89b-12d3-a456-42661417403"
},
{
"id": "123e4567-e89b-12d3-a456-42661417406",
"name": "Control Flow",
"description": "Learn about loops and conditionals in Python.",
"content": "In this lesson, you will learn how to use loops and conditionals in Python.",
"role": "TEXT",
"courseId": "123e4567-e89b-12d3-a456-42661417402"
}
]Route: GET /courses/:id
Description: Finds a course by ID.
Response:
{
"id": "123e4567-e89b-12d3-a456-42661417402",
"name": "Introduction to Programming",
"description": "Learn the basics of programming.",
"banner": "https://example.com/images/programming.jpg",
"createdAt": "2023-04-01T00:00:00Z",
"updatedAt": "2023-04-01T00:00:00Z"
}Route: GET /courses/:courseId/lessons/:id
Description: Finds a lesson by ID for a specific course and watching lesson for students.
Response:
{
"id": "123e4567-e89b-12d3-a456-42661417403",
"name": "Getting Started with Python",
"description": "Learn how to write your first Python program.",
"content": "In this lesson, you will learn how to write a simple Python program.",
"role": "TEXT",
"courseId": "123e4567-e89b-12d3-a456-42661417402"
}Route: PUT /courses/:id
Description: Updates a course by ID.
Request Body:
{
"name": "Advanced Introduction to Programming",
"description": "Dive deeper into the basics of programming.",
"banner": "https://example.com/images/advanced-programming.jpg"
}Response:
{
"id": "123e4567-e89b-12d3-a456-42661417402",
"name": "Advanced Introduction to Programming",
"description": "Dive deeper into the basics of programming.",
"banner": "https://example.com/images/advanced-programming.jpg",
"createdAt": "2023-04-01T00:00:00Z",
"updatedAt": "2023-04-02T00:00:00Z"
}Route: PUT /courses/:courseId/lessons/:id
Description: Updates a lesson by ID for a specific course.
Request Body:
{
"name": "Advanced Python Programming",
"description": "Dive deeper into Python programming.",
"content": "In this lesson, you will learn advanced Python programming concepts.",
"role": "TEXT"
}Response:
{
"id": "123e4567-e89b-12d3-a456-42661417403",
"name": "Advanced Python Programming",
"description": "Dive deeper into Python programming.",
"content": "In this lesson, you will learn advanced Python programming concepts.",
"role": "TEXT",
"courseId": "123e4567-e89b-12d3-a456-42661417402"
}Route: DELETE /courses/:id
Description: Deletes a course by ID.
Response:
{
"message": "Course deleted successfully"
}Route: DELETE /courses/:courseId/lessons/:id
Description: Deletes a lesson by ID for a specific course.
Response:
{
"message": "Lesson deleted successfully"
}