Skip to content

deyperfect/Online-Course-Booking-API

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

8 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Online Course Booking API

A RESTful API for managing online course bookings built with Node.js, Express, and MongoDB. This API provides comprehensive functionality for course management, user authentication, and booking operations.

Node.js Express.js MongoDB

Table of Contents

Features

  • πŸ” User Authentication & Authorization - Secure JWT-based authentication
  • πŸ“š Course Management - CRUD operations for courses with admin controls
  • πŸŽ“ Enrollment System - Enroll in courses and manage enrollments
  • πŸ‘₯ User Management - User registration, login, and profile management
  • πŸ”’ Role-Based Access Control - Different permissions for admin and regular users
  • πŸ“ Course Archiving - Soft delete functionality for courses
  • βœ… Input Validation - Comprehensive request validation
  • πŸ›‘οΈ Security - Protection against common vulnerabilities

Tech Stack

  • Runtime: Node.js
  • Framework: Express.js
  • Database: MongoDB
  • Authentication: JSON Web Tokens (JWT)
  • Password Hashing: bcrypt
  • Environment Variables: dotenv

Getting Started

Prerequisites

Before running this project, ensure you have the following installed:

Installation

  1. Clone the repository
git clone https://github.com/deyperfect/Online-Course-Booking-API.git
  1. Install dependencies
npm install
  1. Set up environment variables

Create a .env file in the root directory:

PORT=4000
MONGODB_URI=
JWT_SECRET=

# Add your MongoDB connection string and set your JWT secret key
  1. Start the server
# Development mode
npm run dev

# Production mode
npm start

The API will be available at http://localhost:4000

Environment Variables

Variable Description Required
PORT Port number for the server Yes
MONGODB_URI MongoDB connection string Yes
JWT_SECRET Secret key for JWT signing Yes

πŸ“š API Documentation

Complete API documentation is available on Postman:

View API Documentation

Base URL

http://localhost:4000

Authentication

Most endpoints require authentication. Include the JWT token in the Authorization header:

Authorization: Bearer <your_jwt_token>

Main Endpoints

Users

  • POST /users/register - Register a new user
  • POST /users/login - Login user
  • GET /users/details - Get user details (requires authentication)
  • PATCH /users/update-password - Update user password

Courses

  • GET /courses/all - Get all active courses
  • GET /courses/:courseId - Get single course details
  • POST /courses/ - Create a new course (Admin only)
  • PATCH /courses/:courseId - Update course (Admin only)
  • PATCH /courses/:courseId/archive - Archive a course (Admin only)

Enrollments

  • POST /enrollments/enroll - Enroll in a course
  • GET /enrollments/my-enrollments - Get user's enrollments

πŸ“ Project Structure

Online-Course-Booking-API/
β”œβ”€β”€ controllers/          # Route controllers (business logic)
β”œβ”€β”€ models/              # Database models (schemas)
β”œβ”€β”€ routes/              # API routes
β”œβ”€β”€ auth.js              # Authentication middleware
β”œβ”€β”€ index.js             # Application entry point
β”œβ”€β”€ package.json         # Project dependencies
β”œβ”€β”€ .gitignore          # Git ignore rules
└── README.md           # Project documentation

Folder Descriptions

  • controllers/ - Contains controller functions that handle the business logic for each route
  • models/ - Mongoose schemas and models for MongoDB collections
  • routes/ - Express route definitions that map URLs to controller functions
  • auth.js - Authentication and authorization middleware

πŸ’‘ Usage Examples

Register a New User

POST /users/register
Content-Type: application/json

{
  "firstName": "John",
  "lastName": "Doe",
  "email": "john@example.com",
  "password": "securePassword123",
  "mobileNo": "09123456789"
}

Login

POST /users/login
Content-Type: application/json

{
  "email": "john@example.com",
  "password": "securePassword123"
}

// Response includes JWT token
{
  "access": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
}

Get User Details

GET /users/details
Authorization: Bearer <your_jwt_token>

// Returns user profile information

Create a Course (Admin)

POST /courses/
Authorization: Bearer <admin_token>
Content-Type: application/json

{
  "name": "Advanced JavaScript",
  "description": "Learn advanced JavaScript concepts and modern frameworks",
  "price": 2999
}

Get All Courses

GET /courses/all

// Returns list of all active courses

Enroll in a Course

POST /enrollments/enroll
Authorization: Bearer <user_token>
Content-Type: application/json

{
  "courseId": "60d5ec49f1b2c72b8c8e4a1b"
}

Get My Enrollments

GET /enrollments/my-enrollments
Authorization: Bearer <user_token>

// Returns all courses the user is enrolled in

Author

deyperfect

For detailed API endpoint documentation and request/response examples, visit the Postman Documentation.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published