Backend Routes - TheCyberLocal/MyTube GitHub Wiki

This wiki provides a comprehensive list of backend routes for our project, detailing each route along with example request bodies and expected responses. The routes are grouped by resource type.

Table of Contents

  1. Auth Routes
  2. User Routes
  3. Videos
  4. Notes
  5. Highlights
  6. Tags

Auth Routes

Sure, here is the updated Auth section of the backend routes for the wiki:

Auth Routes

  1. GET /auth/

    • Description: Authenticates a user. If the user is authenticated, returns the user's details; otherwise, returns an unauthorized error.
    • Example Response:
      {
        "id": 1,
        "username": "johndoe",
        "name": "John Doe",
        "email": "[email protected]",
        "theme": "dark",
        "language": "en"
      }
      
    • Example Response (when not authenticated):
      {
        "errors": {
          "message": "Unauthorized"
        }
      }
      
  2. POST /auth/login

    • Description: Logs a user in.
    • Example Request Body:
      {
        "credential": "[email protected]",
        "password": "securepassword"
      }
      
    • Example Response:
      {
        "id": 1,
        "username": "johndoe",
        "name": "John Doe",
        "email": "[email protected]",
        "theme": "dark",
        "language": "en"
      }
      
    • Example Response (when login fails):
      {
        "errors": {
          "credential": ["Invalid email address or username."],
          "password": ["Invalid password."]
        }
      }
      
  3. POST /auth/logout

    • Description: Logs a user out.
    • Example Response:
      {
        "message": "User logged out"
      }
      
  4. POST /auth/signup

    • Description: Creates a new user and logs them in.
    • Example Request Body:
      {
        "username": "johndoe",
        "name": "John Doe",
        "email": "[email protected]",
        "password": "securepassword"
      }
      
    • Example Response:
      {
        "id": 1,
        "username": "johndoe",
        "name": "John Doe",
        "email": "[email protected]",
        "theme": "light",
        "language": "en"
      }
      
    • Example Response (when signup fails):
      {
        "errors": {
          "username": ["This field is required."],
          "name": ["This field is required."],
          "email": ["Invalid email address."],
          "password": ["This field is required."]
        }
      }
      
  5. GET /auth/unauthorized

    • Description: Returns an unauthorized error message when flask-login authentication fails.
    • Example Response:
      {
        "errors": {
          "message": "Unauthorized"
        }
      }
      

User Routes

  1. PATCH /users/:id

    • Description: Update a user profile by ID.
    • Example Request Body:
      {
        "theme": "dark",
        "language": "fr"
      }
      
    • Example Response:
      {
        "id": 1,
        "username": "john_doe",
        "name": "John Doe",
        "email": "[email protected]",
        "theme": "light",
        "language": "fr"
      }
      
  2. DELETE /users/:id

    • Description: Delete a user by ID.
    • Example Response:
      {
        "message": "User deleted successfully"
      }
      

Videos

  1. GET /my-videos?params

    • Description: Fetch videos associated with the authenticated user.
    • Params: tags, keyword, order_by, and page.
    • Example Response:
      [
        {
          "id": 1,
          "user_id": 1,
          "title": "Sample Video",
          "description": "A sample video description.",
          "url": "https://youtu.be/lTRiuFIWV54",
          "tags": [
             {
                 "id": 1,
                 "name": "Music"
             },
          ],
          "last_viewed": "2023-07-09T12:34:56Z",
          "created_at": "2023-07-09T12:00:00Z",
          "updated_at": "2023-07-09T12:00:00Z"
        }
        {
          "id": 2,
          "user_id": 1,
          "title": "Another Video",
          "description": "Another video description.",
          "url": "https://youtu.be/wAPCSnAhhC8",
          "tags": [
             {
                 "id": 1,
                 "name": "Music"
             },
          ],
          "last_viewed": "2023-07-09T12:34:56Z",
          "created_at": "2023-07-09T12:00:00Z",
          "updated_at": "2023-07-09T12:00:00Z"
        }
      ]
      
  2. GET /videos/:id

    • Description: Fetch a single video by ID.
    • Example Response:
      {
        "id": 1,
        "user_id": 1,
        "title": "Sample Video",
        "description": "A sample video description.",
        "url": "https://youtu.be/lTRiuFIWV54",
        "tags": [
          {
            "id": 1,
            "name": "Sample Tag"
          },
          {
            "id": 2,
            "name": "Another Tag"
          }
        ],
        "highlights": [
          {
            "id": 1,
            "video_id": 1,
            "title": "My Highlight Title",
            "start_time": 0,
            "end_time": 30
          },
          {
            "id": 2,
            "video_id": 1,
            "title": "Another Highlight Title",
            "start_time": 60,
            "end_time": 90
          }
        ],
        "notes": [
          {
            "id": 1,
            "video_id": 1,
            "title": "My Note Title",
            "description": "My description.",
            "created_at": "2023-07-09T12:00:00Z",
            "updated_at": "2023-07-09T12:34:56Z"
          },
          {
            "id": 2,
            "video_id": 1,
            "title": "Another Note Title",
            "description": "Another description.",
            "created_at": "2023-07-09T12:00:00Z",
            "updated_at": "2023-07-09T12:34:56Z"
          }
        ],
        "last_viewed": "2023-07-09T12:34:56Z",
        "created_at": "2023-07-09T12:00:00Z",
        "updated_at": "2023-07-09T12:00:00Z"
      }
      
  3. POST /videos

    • Description: Create a new video.
    • Example Request Body:
      {
        "title": "Sample Video",
        "description": "A sample video description.",
        "url": "https://youtu.be/lTRiuFIWV54",
        "tags": [1, 2]
      }
      
    • Example Response:
      {
        "id": 1,
        "user_id": 1,
        "title": "Sample Video",
        "description": "A sample video description.",
        "url": "https://youtu.be/lTRiuFIWV54",
        "tags": [
          {
            "id": 1,
            "name": "Sample Tag"
          },
          {
            "id": 2,
            "name": "Another Tag"
          }
        ],
        "notes": [],
        "highlights": [],
        "last_viewed": "2023-07-09T12:00:00Z",
        "created_at": "2023-07-09T12:00:00Z",
        "updated_at": "2023-07-09T12:00:00Z"
      }
      
  4. PATCH /videos/:id

    • Description: Update a video by ID.
    • Example Request Body:
      {
        "title": "Updated Video Title",
        "description": "Updated description."
      }
      
    • Example Response:
      {
        "id": 1,
        "user_id": 1,
        "title": "Updated Video Title",
        "description": "Updated description.",
        "url": "https://youtu.be/lTRiuFIWV54",
        "tags": [],
        "notes": [],
        "highlights": [],
        "last_viewed": "2023-07-09T12:34:56Z",
        "created_at": "2023-07-09T12:00:00Z",
        "updated_at": "2023-07-09T12:00:00Z"
      }
      
  5. DELETE /videos/:id

    • Description: Delete a video by ID.
    • Example Response:
      {
        "message": "Video deleted successfully"
      }
      

Notes

  1. GET /videos/:video_id/notes

    • Description: Fetch notes associated with a video.
    • Example Response:
      [
        {
          "id": 1,
          "video_id": 1,
          "title": "Sample Note",
          "description": "A sample note description.",
          "created_at": "2023-07-09T12:00:00Z",
          "updated_at": "2023-07-09T12:00:00Z"
        }
      ]
      
  2. GET /notes/:id

    • Description: Fetch a single note by ID.
    • Example Response:
      {
        "id": 1,
        "video_id": 1,
        "title": "Sample Note",
        "description": "A sample note description.",
        "created_at": "2023-07-09T12:00:00Z",
        "updated_at": "2023-07-09T12:00:00Z"
      }
      
  3. POST /notes

    • Description: Create a new note.
    • Example Request Body:
      {
        "video_id": 1,
        "title": "Sample Note",
        "description": "A sample note description."
      }
      
    • Example Response:
      {
        "id": 1,
        "video_id": 1,
        "title": "Sample Note",
        "description": "A sample note description.",
        "created_at": "2023-07-09T12:00:00Z",
        "updated_at": "2023-07-09T12:00:00Z"
      }
      
  4. PATCH /notes/:id

    • Description: Update a note by ID.
    • Example Request Body:
      {
        "title": "Updated Note Title",
        "description": "Updated description."
      }
      
    • Example Response:
      {
        "id": 1,
        "video_id": 1,
        "title": "Updated Note Title",
        "description": "Updated description.",
        "created_at": "2023-07-09T12:00:00Z",
        "updated_at": "2023-07-09T12:34:56Z"
      }
      
  5. DELETE /notes/:id

    • Description: Delete a note by ID.

    • Example Response:

      {
        "message": "Note deleted successfully"
      }
      

Highlights

  1. GET /videos/:video_id/highlights

    • Description: Fetch highlights associated with a video.
    • Example Response:
      [
        {
          "id": 1,
          "video_id": 1,
          "title": "Sample Highlight",
          "start_time": 0,
          "end_time": 15,
          "created_at": "2023-07-09T12:00:00Z",
          "updated_at": "2023-07-09T12:00:00Z"
        },
        {
          "id": 2,
          "video_id": 1,
          "title": "Another Highlight",
          "start_time": 30,
          "end_time": 45,
          "created_at": "2023-07-09T12:00:00Z",
          "updated_at": "2023-07-09T12:00:00Z"
        }
      ]
      
  2. GET /highlights/:id

    • Description: Fetch a single highlight by ID.
    • Example Response:
      {
        "id": 1,
        "video_id": 1,
        "title": "Sample Highlight",
        "start_time": 30,
        "end_time": 45,
        "created_at": "2023-07-09T12:00:00Z",
        "updated_at": "2023-07-09T12:00:00Z"
      }
      
  3. POST /highlights

    • Description: Create a new highlight.
    • Example Request Body:
      {
        "video_id": 1,
        "title": "Sample Highlight",
        "start_time": 30,
        "end_time": 45
      }
      
    • Example Response:
      {
        "id": 1,
        "video_id": 1,
        "title": "Sample Highlight",
        "start_time": 30,
        "end_time": 45,
        "created_at": "2023-07-09T12:00:00Z",
        "updated_at": "2023-07-09T12:00:00Z"
      }
      
  4. PATCH /highlights/:id

    • Description: Update a highlight by ID.
    • Example Request Body:
      {
        "title": "Updated Highlight Name",
        "start_time": 15
      }
      
    • Example Response:
      {
        "id": 1,
        "video_id": 1,
        "title": "Updated Highlight Name",
        "start_time": 15,
        "end_time": 45,
        "created_at": "2023-07-09T12:00:00Z",
        "updated_at": "2023-07-09T12:00:00Z"
      }
      
  5. DELETE /highlights/:id

    • Description: Delete a highlight by ID.
    • Example Response:
      {
        "message": "Highlight deleted successfully"
      }
      

Tags

  1. GET /videos/:video_id/tags

    • Description: Fetch tags associated with a video.
    • Example Response:
      [
        {
          "id": 1,
          "name": "Sample Tag"
        }
      ]
      
  2. GET /tags/:id

    • Description: Fetch a single tag by ID.
    • Example Response:
      {
        "id": 1,
        "name": "Sample Tag"
      }
      
  3. GET /tags

    • Description: Fetch all tags.
    • Example Response:
      [
        {
          "id": 1,
          "name": "Sample Tag"
        }
      ]
      
  4. POST /tags (currently disabled)

    • Description: Create a new tag.
    • Example Request Body:
      {
        "name": "Sample Tag"
      }
      
    • Example Response:
      {
        "id": 1,
        "name": "Sample Tag"
      }
      
  5. PATCH /tags/:id (currently disabled)

    • Description: Update a tag by ID.
    • Example Request Body:
      {
        "name": "Updated Tag Name"
      }
      
    • Example Response:
      {
        "id": 1,
        "name": "Updated Tag Name"
      }
      
  6. DELETE /tags/:id (currently disabled)

    • Description: Delete a tag by ID.
    • Example Response:
      {
        "message": "Tag deleted successfully"
      }