📘 LearnTube API Documentation

🔐 Auth Routes

POST /auth/register

Register a new user

Request Body:
{
  "name": "Budi",
  "email": "budi@example.com",
  "password": "password123"
}
Response:
{
  "success": true,
  "message": "User created successfully. Please check your email for verification.",
  "user": {
    "id": "xxx",
    "email": "budi@example.com",
    "name": "Budi",
    "role": "user"
  }
}

POST /auth/login

Login and get a JWT token

Request Body:
{
  "email": "budi@example.com",
  "password": "password123"
}
Response:
{
  "success": true,
  "message": "Login successful",
  "token": "jwt-token",
  "user": {
    "id": "xxx",
    "email": "budi@example.com",
    "name": "Budi",
    "role": "user",
    "isVerified": "true",
    "authType": "local",
    "avatar": ""
  }
}

GET /auth/profile

Get the profile of the logged-in user

Headers:
Authorization: Bearer <token>
Response:
{
  "success": true,
  "user": {
    "id": "xxx",
    "name": "Budi",
    "email": "budi@example.com",
    "role": "user"
  }
}

GET /auth/verify/:token

Verify email from token

Response:
{
  "success": true,
  "message": "Email successfully verified."
}

👥 User Routes

GET /users

Get all users (Admin only)

Headers:
Authorization: Bearer <admin_token>
Response:
{
  "success": true,
  "users": [
    {
      "id": "xxx",
      "name": "Budi",
      "email": "budi@example.com",
      "role": "user"
    }
  ]
}

GET /users/:id

Get user details (Admin or the user themselves)

Headers:
Authorization: Bearer <token>
Response:
{
  "success": true,
  "user": {
    "id": "xxx",
    "name": "Budi",
    "email": "budi@example.com",
    "role": "user"
  }
}

PUT /users/:id

Update user (Admin or the user themselves)

Headers:
Authorization: Bearer <token>
Request Body:
{
  "name": "Budi Update",
  "email": "budi@baru.com"
}
Response:
{
  "success": true,
  "message": "User updated successfully",
  "user": {
    "id": "xxx",
    "name": "Budi Update",
    "email": "budi@baru.com",
    "role": "user"
  }
}

DELETE /users/:id

Delete user (Admin only)

Headers:
Authorization: Bearer <admin_token>
Response:
{
  "success": true,
  "message": "User deleted successfully"
}

📚 Playlist Routes

POST /playlist/create

Create a new playlist (Max 10 playlists per user)

Headers:
Authorization: Bearer <token>
Request Body:
{
  "title": "JavaScript Learning Path"
}
Response:
{
  "success": true,
  "message": "Playlist created successfully",
  "playlist": {
    "id": "xxx",
    "title": "JavaScript Learning Path",
    "owner": "user_id",
    "roadmaps": []
  }
}

GET /playlist/user

Get all playlists of the user

Headers:
Authorization: Bearer <token>
Response:
{
  "success": true,
  "playlists": [
    {
      "id": "xxx",
      "title": "JavaScript Learning Path",
      "owner": "user_id",
      "roadmaps": []
    }
  ]
}

PUT /playlist/update-playlist/:playlistId

Update playlist (Owner or Admin only)

Headers:
Authorization: Bearer <token>
Request Body:
{
  "title": "Updated JavaScript Learning Path"
}
Response:
{
  "success": true,
  "message": "Playlist updated successfully",
  "playlist": {
    "id": "xxx",
    "title": "Updated JavaScript Learning Path",
    "owner": "user_id"
  }
}

DELETE /playlist/delete-playlist/:playlistId

Delete playlist (Owner or Admin only)

Headers:
Authorization: Bearer <token>
Response:
{
  "success": true,
  "message": "Playlist deleted successfully"
}

🛣️ Roadmap Routes

POST /playlist/create-roadmap/:playlistId

Create a new roadmap in a playlist (Owner or Admin only)

Headers:
Authorization: Bearer <token>
Request Body:
{
  "title": "Beginner"
}
Response:
{
  "success": true,
  "message": "Roadmap created successfully",
  "roadmap": {
    "id": "xxx",
    "title": "Beginner",
    "videos": []
  }
}

GET /playlist/roadmap/:playlistId

Get all roadmaps in a playlist

Headers:
Authorization: Bearer <token>
Response:
{
  "success": true,
  "roadmaps": [
    {
      "id": "xxx",
      "title": "Beginner",
      "videos": []
    }
  ]
}

GET /playlist/roadmap/:playlistId/:roadmapId

Get a specific roadmap detail

Headers:
Authorization: Bearer <token>
Response:
{
  "success": true,
  "roadmap": {
    "id": "xxx",
    "title": "Beginner",
    "videos": [
      {
        "videoId": "xyz123",
        "title": "JavaScript Tutorial for Beginners",
        "url": "https://youtube.com/watch?v=xyz123",
        "progress": "Not Started"
      }
    ]
  }
}

PUT /playlist/update-roadmap/:playlistId/:roadmapId

Update roadmap (Owner or Admin only)

Headers:
Authorization: Bearer <token>
Request Body:
{
  "newTitle": "Beginner Level"
}
Response:
{
  "success": true,
  "message": "Roadmap updated successfully",
  "roadmap": {
    "id": "xxx",
    "title": "Beginner Level",
    "videos": []
  }
}

DELETE /playlist/delete-roadmap/:playlistId/:roadmapId

Delete roadmap (Owner or Admin only)

Headers:
Authorization: Bearer <token>
Response:
{
  "success": true,
  "message": "Roadmap deleted successfully"
}

🎬 Video Routes

GET /playlist/search

Search for videos from the YouTube API

Headers:
Authorization: Bearer <token>
Query Parameters:
q=javascript // search query
Response:
{
  "success": true,
  "videos": [
    {
      "videoId": "xyz123",
      "title": "JavaScript Tutorial for Beginners",
      "description": "Learn JavaScript from scratch",
      "thumbnail": "https://i.ytimg.com/vi/xyz123/default.jpg",
      "channelTitle": "Coding Channel",
      "publishedAt": "2023-01-01T00:00:00Z"
    }
  ]
}

POST /playlist/add-video/:playlistId/:roadmapId

Add a video to a roadmap (Max 3 videos per roadmap)

Headers:
Authorization: Bearer <token>
Request Body:
{
  "videoData": {
    "videoId": "xyz123",
    "videoTitle": "JavaScript Tutorial for Beginners",
    "videoUrl": "https://youtube.com/watch?v=xyz123"
  }
}
Response:
{
  "success": true,
  "message": "Video added successfully",
  "video": {
    "videoId": "xyz123",
    "title": "JavaScript Tutorial for Beginners",
    "url": "https://youtube.com/watch?v=xyz123",
    "progress": "Not Started"
  }
}

PUT /playlist/update-progress/:playlistId/:roadmapId

Update video progress (In Progress/Completed)

Headers:
Authorization: Bearer <token>
Request Body:
{
  "videoId": "xyz123",
  "progress": "Completed"
}
Response:
{
  "success": true,
  "message": "Video progress updated successfully",
  "video": {
    "videoId": "xyz123",
    "progress": "Completed"
  }
}

DELETE /playlist/delete-video/:playlistId/:roadmapId/:videoId

Delete video from roadmap

Headers:
Authorization: Bearer <token>
Response:
{
  "success": true,
  "message": "Video deleted successfully"
}

🔜 Coming Soon Features

The following features are planned for future implementation:


All responses are sent in JSON format.