/Clevernote-

Primary LanguageJavaScript

Clevernote-

API Reference - Backend

NOTEBOOKS

Get all Notebooks from current user

Returns all Notebooks created by the current user.

  • Require Authentication: True

  • Request:

    • Method: GET
    • URL: /notebooks
    • Body: none
  • Successful Response

    • Status Code: 200
    • Headers:
      • Content-Type: application/json
    • Body:
          {
          "Notebooks": [{
              "id": 1,
              "title": "Joe's Notebook",
              "user_id": 3,
              "created_at": "2021-11-19 20:39:36",
              "updated_at": "2021-11-19 20:39:36"
          }]
          }

Get all data from a specific Notebook

Returns all notes inside of selected Notebook.

  • Require Authentication: True

  • Request:

    • Method: GET
    • URL: /notebooks/:id ?/note?
    • Body: none
  • Successful Response

    • Status Code: 200
    • Headers:
      • Content-Type: application/json
    • Body:
          {
          "id": 1,
          "title": "Joe's Notebook",
          "user_id": 3,
          "created_at": "2021-11-19 20:39:36",
          "updated_at": "2021-11-19 20:39:36",
          "Notes": [{
              "id": 1,
              "title": "Joes Notebook",
              "content": "Stuff",
              "notebook_id": 1,
              "user_id": 3,
              "created_at": "2021-11-19 20:39:36",
              "updated_at": "2021-11-19 20:39:36"
          }]
          }

Create a Notebook

Creates and returns a new Notebook.

  • Require Authentication: True

  • Request:

    • Method: POST
    • URL: /notebooks
    • Headers:
      • Content-Type: application/json
    • Body:
          {
          "title": "Tom's Notebook",
          "user_id": 4,
          }
  • Successful Response

    • Status Code: 201
    • Headers:
      • Content-Type: application/json
    • Body:
          {
          "id": 2,
          "title": "Tom's Notebook",
          "user_id": 4,
          "created_at": "2021-11-19 20:39:36",
          "updated_at": "2021-11-19 20:39:36",
          }
  • Error Response: Body validation errors

    • Status Code: 400

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "message": "Bad Request",
        "errors": {
          "title": "Title is required."
        }
      }

Adding a Note to a Notebook

Adds the note to the notebook and then returns the note.

  • Require Authentication: True

  • Request:

    • Method: POST
    • URL: /notes/:id/notebooks
    • Headers:
      • Content-Type: application/json
    • Body:
          {
              "notebook_id": 2
          }
  • Successful Response

    • Status Code: 201
    • Headers:
      • Content-Type: application/json
    • Body:
          {
          "id": 1,
          "title": "Tom's Note",
          "notebook_id": 2,
          "user_id": 4,
          "created_at": "2021-11-19 20:39:36",
          "updated_at": "2021-11-19 20:39:36",
          }
  • Error response: Couldn't find a Notebook with the specified id

    • Status Code: 404

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "message": "Notebook couldn't be found"
      }

Edit a Notebook

Updates and returns an existing notebook.

  • Require Authentication: True

  • Require proper authorization: Notebook must belong to the current user

  • Request

    • Method: PUT

    • URL: /notebooks/:id

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "title": "Peter's Notebook"
      }
  • Successful Response

    • Status Code: 200

    • Headers:

      • Content-Type: application/json
    • Body:

      {
          "id": 2,
          "title": "Peter's Notebook",
      }
  • Error Response: Body validation errors

    • Status Code: 400

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "message": "Bad Request", // (or "Validation error" if generated by Sequelize),
        "errors": {
          "title": "Title is required"
        }
      }
  • Error response: Couldn't find a Notebook with the specified id

    • Status Code: 404

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "message": "Notebook couldn't be found"
      }

Delete a Notebook

Deletes an existing notebook.

  • Require Authentication: True

  • Require proper authorization: Notebook must belong to the current user

  • Request

    • Method: DELETE
    • URL: /notebooks/:id
    • Body: none
  • Successful Response

    • Status Code: 200

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "message": "Successfully deleted"
      }
  • Error response: Couldn't find a Notebook with the specified id

    • Status Code: 404

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "message": "Notebook couldn't be found"
      }

Tasks

Create a New Task

A logged-in user can create a new task.

POST /api/tasks

Require Authentication: True

Request Body:

{

"title": "Buy groceries",

"description": "Get milk, bread, and eggs",

"status": "pending",

"due_date": "2024-08-01"

}

Response:

Status Code: 201

Headers: Content-Type: application/json

Body:

{

"id": 1,

"user_id": 1,

"title": "Buy groceries",

"description": "Get milk, bread, and eggs",

"status": "pending",

"due_date": "2024-08-01",

"created_at": "2024-07-24T14:15:22Z",

"updated_at": "2024-07-24T14:15:22Z"

}

Error Response:

Status Code: 400

Headers: Content-Type: application/json

Body:

{

"message": "Bad Request",

"errors": { "title" : "Title is required", "description" : "Description is required" }

}

View All Tasks

A logged-in user can view all of their tasks.

GET/api/tasks

Require Authentication: True

Succesful Response:

Status Code: 200

Headers: Content-Type: application/json

Body:

[

{

"id": 1,

"user_id": 1,

"title": "Buy groceries",

"description": "Get milk, bread, and eggs",

"status": "pending",

"due_date": "2024-08-01",

"created_at": "2024-07-24T14:15:22Z",

"updated_at": "2024-07-24T14:15:22Z"

},

{

"id": 2,

"user_id": 1,

"title": "Finish project",

"description": "Complete the Clevernote project",

"status": "completed",

"due_date": "2024-07-25",

"created_at": "2024-07-24T14:20:22Z",

"updated_at": "2024-07-24T14:20:22Z"

}

]

Status Code: 401

Headers: Content-Type: application/json

Body:

{

"message": "Unauthorized"

}

View a Single Task

A logged-in user can view a specific task.

GET /api/tasks/:id

Require Authentication: True

Succesful Response:

{

"id": 1,

"user_id": 1,

"title": "Buy groceries",

"description": "Get milk, bread, and eggs",

"status": "pending",

"due_date": "2024-08-01",

"created_at": "2024-07-24T14:15:22Z",

"updated_at": "2024-07-24T14:15:22Z"

}

Error Response:

Status Code: 404

Headers: Content-Type: application/json

Body:

{

"message": "Task not found"

}

Update a Task

A logged-in user can update an existing task.

PUT /api/tasks/:id

Require Authentication: True

Request Body:

{

"title": "Buy groceries and vegetables",

"description": "Get milk, bread, eggs, and carrots",

"status": "pending",

"due_date": "2024-08-02"

}

Successful Response:

Status Code: 200

Headers: Content-Type: application/json

Body:

{

"id": 1,

"user_id": 1,

"title": "Buy groceries and vegetables",

"description": "Get milk, bread, eggs, and carrots",

"status": "pending",

"due_date": "2024-08-02",

"created_at": "2024-07-24T14:15:22Z",

"updated_at": "2024-07-24T14:30:22Z"

}

Error Response:

Status Code: 400

Headers: Content-Type: application/json

Body:

{

"message": "Bad Request",

"errors": { "title" : "Title is required", "description" : "Description is required" }

}

Delete a Task

A logged-in user can delete a task.

DELETE /api/tasks/:id

Require Authentication: True

Successful Response:

Status Code: 200

Headers: Content-Type: application/json

Body:

{

"message": "Task deleted successfully."

}

Error Response:

Status Code: 404

Headers: Content-Type: application/json

Body:

{

"message": "Task not found"

}

Mark Task as Completed

A logged-in user can mark a task as completed.

PUT /api/tasks/:id/completed

Require Authentication: True

Request Body:

{

"status": "completed"

}

Succesful Response:

Status Code: 200

Headers: Content-Type: application/json

Body:

{

"id": 1,

"user_id": 1,

"title": "Buy groceries",

"description": "Get milk, bread, and eggs",

"status": "completed",

"due_date": "2024-08-01",

"created_at": "2024-07-24T14:15:22Z",

"updated_at": "2024-07-24T14:45:22Z"

}

Error Response:

Status Code: 400

Headers: Content-Type: application/json

Body:

{

"message": "Bad Request",

"errors": { "status" : "Status is required" }

}

Search Tasks by Title

A logged-in user can search for tasks by title.

GET /api/tasks/search?title=:title

Require Authentication: True

Successful Response:

Status Code: 200

Headers: Content-Type: application/json

Body:

[

{

"id": 1,

"user_id": 1,

"title": "Buy groceries",

"description": "Get milk, bread, and eggs",

"status": "pending",

"due_date": "2024-08-01",

"created_at": "2024-07-24T14:15:22Z",

"updated_at": "2024-07-24T14:15:22Z"

}

]

Error Response:

Status Code: 404

Headers: Content-Type: application/json

Body:

{

"message": "No tasks found"

}

Filtering Tasks by Status

A logged-in user can filter tasks by their status.

GET /api/tasks?status=:status

Require Authentication: True

Succesful Response:

Status Code: 200

Headers: Content-Type: application/json

Body:

[

{

"id": 2,

"user_id": 1,

"title": "Finish project",

"description": "Complete the Clevernote project",

"status": "completed",

"due_date": "2024-07-25",

"created_at": "2024-07-24T14:20:22Z",

"updated_at": "2024-07-24T14:20:22Z"

}

]

Error Response:

Status Code: 404

Headers: Content-Type: application/json

Body:

{

"message": "No tasks found"

}

Notes

Get notes of current user - Returns all the notes of the current user

Require Authentication: true

Request

  • Method: GET
  • URL: /api/notes
  • Body: none

Successful Response

  • Status Code: 200
  • Headers: Content-Type: application/json
  • Body:

[

{ “id”: 1, “title”: “Test Note 1”, “content”: “This is a test note”, “notebookId”: 1, “userId”: 1, “created_at”: “2024-07-24 19:42:13.424242”, “updated_at”: null },

{ “id”: 2, “Title”: “Test Note 2”, “Content”: “This is another test note”, “NotebookId”: 2, “userId”: 1, “created_at”: “2024-07-24 19:42:13.424243”, “updated_at”: null }

]

Create a note - creates a new note ready to be updated

Require Authentication: true

Request

  • Method: POST *URL: /api/notes
  • Body:

{

“Title” : “Testing Clevernote”,

“Content”: “Note for testing 1”

}

Successful Response

  • Status Code: 201
  • Headers: Content-Type: application/json
  • Body:

[

{ “id”: 5, “Title”: “Testing Clevernote”, “Content”: “Note for testing 1”, “NotebookId”: 4, “userId”: 3, “created_at”: “2024-07-24 19:58:13.4242” “Updated_at”: null }

]

Error Response

  • Status Code: 400
  • Headers: Content-Type: application/json
  • Body:

{

“Message”: “Bad Request”,

“errors”: { “title” : “Title is required”, “content” : “Content is required” }

}

Update a note - update a note, autosave

Request

  • Method: PUT
  • URL: /api/notes/:noteid
  • Headers: Content-Type: application/json
  • Body:

{

“Title”: “Edit Title 1”,

“Content”: “Edit this content”,

“NotebookId”: 5

}

Successful Response

  • Status Code: 200
  • Headers: Content-Type: application/json
  • Body:

{

“Id” : 1, “Title”: “Edit Title 1”, “Content”: “Edit this content”, “NotebookId”: 5, “userId”: 3, “created_at”: “2024-07-24 19:58:13.4242”, “Updated_at”: “2024-07-24 20:16:42.1313”

}

Error Response 1

  • Status Code: 400
  • Headers: Content-Type: application/json
  • Body:

{

“Message”: “Bad Request”,

“errors”: { “title” : “Title is required”, “content” : “Content is required” }

}

Error Response 2

  • Status Code: 404
  • Headers: Content-Type: application/json
  • Body:

{ “Message” : “Note couldn’t be found” }

Delete a note - delete a note, update shows the note was deleted without refresh

Require Authentication: true

Request

  • Method: DELETE
  • URL: /api/notes/:noteid
  • Body: none

Successful Response

  • Status Code: 200
  • Headers: Content-Type: application/json
  • Body:

{ “Message” : “Note deleted successfully }

**Error Response **

  • Status Code: 404
  • Headers: Content-Type: application/json
  • Body:

{ “Message” : “Note couldn’t be found” }

Potential API to add in the future for admin reference: get detail of all notes. It could possibly include:

  • noteId
  • title
  • created_at
  • updated_at
  • character_count
  • word_count
  • spaces_count
  • paragraph_count
  • total_updates
  • last_updated

Get all tags from current user

A logged-in user can view all of their created tags

Require Authentication: True

Request:

  • Method: GET
  • URL: /api/tags
  • Headers: Content-Type: application/json
  • Body: none

Successful Response:

  • Status Code: 200
  • Headers: Content-Type: application/json
  • Body: [ { "id": 1 "tagName": "Test Tag 1" "createdAt": 2024-07-25 19:58:13.4242" }, { "id": 2 "tagName": "Test Tag 2" "createdAt": 2024-07-25 19:58:13.4242" } ]

Search for notes associated with a tag

A logged-in user can view their notes which have a specific tag associated with them

Require Authentication: True

Request:

  • Method: GET
  • URL: /api/tags/:tagId/notes
  • Headers: Content-Type: application/json
  • Body: { "id": 1 "tagName": "Test Tag 1" }

Successful Response:

  • Status Code: 200
  • Headers: Content-Type: application/json
  • Body:

{ "id": 1, "tagName": "Test Tag 1" "createdAt": "2024-07-25 19:58:13.4242" "updatedAt": null "noteId": 1 "title": "Sample Note 1" "content": "Sample Note Content Here" }

Error Response:

  • Status Code: 404
  • Headers: Content-Type: application/json
  • Body: { "Message": "Tag could not be found" }

**Create a tag

A logged-in user can create new tags

Require Authentication: True

Request:

  • Method: POST
  • URL: /api/tags
  • Body:

{ tagName: "Test Tag 1" }

Successful Response:

  • Status Code: 200
  • Headers: Content-Type: application/json
  • Body:

{ "id": 1, "tagName": "Test Tag 1" "createdAt": "2024-07-25 19:58:13.4242" "updatedAt": null }

Error Response:

  • Status Code: 400
  • Headers: Content-Type: application/json
  • Body: { "Message": "Bad Request",

"errors": { "tagName": "Tag name is required" } }

Update a tag

A logged-in user can edit and update their tags

Required Authentication: True

Request:

  • Method: PUT
  • URL: /api/tags/:tagId
  • Body:

{ tagName: "Update Tag 1" }

Successful Response:

  • Status Code: 200
  • Headers: Content-Type: application/json
  • Body:

[ { "id": 1, "tagName": "Update Tag 1" "createdAt": "2024-07-25 19:58:13.4242" "updatedAt": 2024-07-25 20:58:13.4242 } ]

Error Response:

  • Status Code: 400
  • Headers: Content-Type: application/json
  • Body: { "Message": "Bad Request",

"errors": { "tagName": "Tag name is required" } }

Error Response 2:

  • Status Code: 404
  • Headers: Content-Type: application/json
  • Body: { "Message": "Tag could not be found" }

Delete a tag

A logged-in user can delete a tag

Require Authentication: True

Request:

  • Method: DELETE
  • URL: /api/tags/:tagId
  • Body: none

Successful Response:

  • Status Code: 200
  • Headers: Content-Type: application/json
  • Body: { "Message": "Tag deleted successfully" }

Error Response:

  • Status Code: 404
  • Headers: Content-Type: application/json
  • Body: { "Message": "Tag could not be found" }

API Reference ‐ Frontend

Notebooks

All Notebooks

  • URL: "/notebooks"
  • Auth Required: True
  • Content:
    • This will show a list of all the user's notebooks

Selected Notebook

  • URL: "/notebooks/:id"
  • Auth Required: True
  • Content:
    • This will show a list of all the notes inside the selected notebook

Edit Selected Notebook

  • URL: "/notebooks/:id/edit"
  • Auth Required: True
  • Content:
    • This will have a form to edit the notebook

Notes

Tasks

GET /tasks

  • Fetches a list of tasks for the logged-in user.
  • Displays task details such as title, description, status, due date, and priority.

POST /tasks

  • Creates a new task with the provided details.

Request Body:

{

"title": "Task Title",

"description": "Task Description",

"status": "pending",

"due_date": "YYYY-MM-DD",

"priority": "low|medium|high"

}

PUT /tasks/

  • Updates an existing task with new details.

Request Body:

{

"title": "Updated Task Title",

"description": "Updated Task Description",

"status": "pending|completed",

"due_date": "YYYY-MM-DD",

"priority": "low|medium|high"

}

DELETE /tasks/

  • Deletes the specified task.

Task Details Page

This page displays the details of a single task, including options to edit or delete the task.

GET /tasks/

  • Fetches the details of a specific task by its ID.
  • Displays task details such as title, description, status, due date, and priority.

POST /tasks/status

  • Updates the status of the specified task.
  • Request Body:

Request Body:

{

"status": "pending|completed"

}

POST /tasks/priority

  • Updates the priority of the specified task.

Request Body:

{

"priority": "low|medium|high"

}

Potential Additional Endpoints

These endpoints allow for managing task attributes such as reminders and tags.

POST /tasks/reminder

  • Sets a reminder for the specified task.

Request Body:

{

"reminder_time": "HH:MM",

"reminder_date": "YYYY-MM-DD"

}

DELETE /tasks/reminder

  • Removes the reminder for the specified task.

POST /tasks/tags

  • Adds tags to the specified task.

Request Body:

{

"tags": ["tag1", "tag2"]

}

DELETE /tasks/tags

  • Removes tags from the specified task.

Request Body:

{

"tags": ["tag1", "tag2"]

}

Tags