API Documentation - RoseMontoya/Luna-AA-Capstone GitHub Wiki

Session/User

Login User

  • Request:

    • Method: POST

    • URL: /api/session

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "email": "[email protected]",
        "password": "secret password"
      }
      
  • Successful Response:

    • Status Code: 200

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "user": {
          "id": 1,
          "firstName": "John",
          "lastName": "Smith",
          "email": "[email protected]",
        }
      }
      
  • Error Response: Invalid credentials

    • Status Code: 401

    • Headers:

      • Content-Type: application/json
    • Body:

      {
       "title": "Login failed",
      "message": "Invalid credentials",
      "errors": {
          "credentials": "Invalid credentials"
      },
      }
      
  • Error response: Body validation errors

    • Status Code: 400

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "title": "Validation error",
        "message": "Validation error",
        "errors": {
          "email": "Email is required",
          "password": "Password is required"
      },
      }
      

Restore User

  • Request:

    • Method: GET
    • URL: /api/session
    • Body: none
  • Successful Response: when there is a logged in user

    • Status Code: 200

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "user": {
          "id": 1,
          "firstName": "John",
          "lastName": "Smith",
          "email": "[email protected]",
        }
      }
      
  • Successful Response: when there is no logged in user

    • Status Code: 200

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "user": null
      }
      

Sign up User

  • Request:

    • Method: POST

    • URL: /api/users

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "firstName": "John",
        "lastName": "Smith",
        "email": "[email protected]",
        "password": "secret password"
      }
      
  • Successful Response:

    • Status Code: 200

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "user": {
          "id": 1,
          "firstName": "John",
          "lastName": "Smith",
          "email": "[email protected]",
        }
      }
      
  • Error response: User already exists with the specified email

    • Status Code: 500

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "title": "User already exists",
        "message": "User already exists",
        "errors": {
          "email": "User with that email already exists"
      },
      }
      
  • Error response: Body validation errors

    • Status Code: 400

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "title": "Validation error",
      "message": "Validation error",
      "errors": {
          "firstName": "First Name is required" || "Name must be at least 2 characters long." || "Name cannot be longer than 30 characters.",
          "lastName": "Last Name is required" || "Name must be at least 2 characters long." || "Name cannot be longer than 75 characters.",
          "email": "Email is required" || "Please provide a valid email.",
          "password": "Password is required" || "Password must be at least 6 characters."
      },
      }
      

Logout User

  • Purpose: Log out user

  • Require Authentication: false

  • Request:

    • Method: DELETE
    • URL: /api/session
    • Headers: none
    • Body: none
  • Successful Response:

    • Status Code: 200

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "message": "success"
      }
      

Entries

Get all entries for a User

  • Purpose: Returns all of a user entries.

  • Require Authentication: true

  • Require proper authorization

  • Request:

    • Method: GET
    • URL: /api/users/:userId/entries
    • Body: none
  • Successful Response:

    • Status Code: 200

    • Headers:

      • Content-Type: application/json
    • Body:

      [
        {
          "EntryActivities": [
            { "entryId": 33, "activityId": 18 },
            { "entryId": 33, "activityId": 19 },
            { "entryId": 33, "activityId": 24 },
            { "entryId": 33, "activityId": 27 },
            { "entryId": 33, "activityId": 28 },
            { "entryId": 33, "activityId": 31 },
            { "entryId": 33, "activityId": 32 }
          ],
          "EntryLevels": [
            { "entryId": 33, "levelId": 6, "rating": 4, "createdAt": "2024-09-03T02:14:33.714Z" },
            { "entryId": 33, "levelId": 7, "rating": 4, "createdAt": "2024-09-03T02:14:33.714Z" },
            { "entryId": 33, "levelId": 8, "rating": 4, "createdAt": "2024-09-03T02:14:33.714Z" },
            { "entryId": 33, "levelId": 9, "rating": 4, "createdAt": "2024-09-03T02:14:33.714Z" },
            { "entryId": 33, "levelId": 10, "rating": 3, "createdAt": "2024-09-03T02:14:33.714Z" }
          ],
          "datetime": "2024-09-03T02:13:00.000Z",
          "iconId": 9,
          "id": 33,
          "mood": "Okay",
          "note": "Had an amazing dinner with Ben. Feeling lucky to have such a supportive partner.",
          "overallMood": 3,
          "userId": 4
        },
      ]
      

Get all entries for today for a user

  • Purpose: Returns all of a user's entries for the current day.

  • Require Authentication: true

  • Require proper authorization

  • Request:

    • Method: GET
    • URL: /api/users/:userId/today
    • Body: none
  • Successful Response:

    • Status Code: 200

    • Headers:

      • Content-Type: application/json
    • Body:

      [
        {
          "EntryActivities": [
            { "entryId": 33, "activityId": 18 },
            { "entryId": 33, "activityId": 19 },
          ],
          "EntryLevels": [
            { "entryId": 33, "levelId": 6, "rating": 4, "createdAt": "2024-09-03T02:14:33.714Z" },
            { "entryId": 33, "levelId": 7, "rating": 4, "createdAt": "2024-09-03T02:14:33.714Z" },
          ],
          "datetime": "2024-09-03T02:13:00.000Z",
          "iconId": 9,
          "id": 33,
          "mood": "Okay",
          "note": "Had an amazing dinner with Ben. Feeling lucky to have such a supportive partner.",
          "overallMood": 3,
          "userId": 4
        },
      ]
      

Get an entry by id

  • Purpose: Returns an entry by entry id.

  • Require Authentication: true

  • Require proper authorization

  • Request:

    • Method: GET
    • URL: /api/entries/:entriesId
    • Body: none
  • Successful Response:

    • Status Code: 200

    • Headers:

      • Content-Type: application/json
    • Body:

        {
          "EntryActivities": [
            { "entryId": 33, "activityId": 18 },
            { "entryId": 33, "activityId": 19 },
          ],
          "EntryLevels": [
            { "entryId": 33, "levelId": 6, "rating": 4, "createdAt": "2024-09-03T02:14:33.714Z" },
            { "entryId": 33, "levelId": 7, "rating": 4, "createdAt": "2024-09-03T02:14:33.714Z" },
          ],
          "datetime": "2024-09-03T02:13:00.000Z",
          "iconId": 9,
          "id": 33,
          "mood": "Okay",
          "note": "Had an amazing dinner with Ben. Feeling lucky to have such a supportive partner.",
          "overallMood": 3,
          "userId": 4
        }
      
  • Error response: Entry not found

    • Status Code: 404

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "title": "Not found",
        "message": "Not found",
        "errors": {
            "message": "Entry not found."
        },
      }
      

Create a new entry

  • Purpose: Creates a new entry for a user

  • Require Authentication: true

  • Require proper authorization

  • Request:

    • Method: POST
    • URL: /api/entries
    • Body:
    {
      "activities": [24, 25, 19],
      "datetime": "Wed Sep 04 2024 10:22:22 GMT-0700 (Pacific Daylight Time)",
      "iconId": 4,
      "levels": [
        { "levelId": 6, "rating": 8 },
        { "levelId": 7, "rating": 8 },
        { "levelId": 8, "rating": 6 },
        { "levelId": 9, "rating": 8 },
        { "levelId": 10, "rating": 8 }
      ],
      "mood": "Determined",
      "note": "I am going to work really hard and get an amazing job!",
      "overallMood": "8"
    }
    
  • Successful Response:

    • Status Code: 201

    • Headers:

      • Content-Type: application/json
    • Body:

      {
      "EntryActivities": [
        { "entryId": 35, "activityId": 19 },
        { "entryId": 35, "activityId": 24 },
        { "entryId": 35, "activityId": 25 }
      ],
      "EntryLevels": [
        { "entryId": 35, "levelId": 6, "rating": 8, "createdAt": "2024-09-04T17:23:35.587Z" },
        { "entryId": 35, "levelId": 7, "rating": 8, "createdAt": "2024-09-04T17:23:35.587Z" },
      ],
      "createdAt": "2024-09-04T17:23:35.570Z",
      "datetime": "2024-09-04T17:22:22.032Z",
      "iconId": 4,
      "id": 35,
      "mood": "Determined",
      "note": "I am going to work really hard and get an amazing job!",
      "overallMood": 8,
      "updatedAt": "2024-09-04T17:23:35.570Z",
      "userId": 4
      }
      
  • Error response: Body validation errors

    • Status Code: 400

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "title": "Validation error",
        "message": "Validation error",
        "errors": {
            "datetime": "Date is required." || "Entry date cannot be in the future." || "Date cannot be before the year 2000.",
            "mood": "Please give a word to describe how you are feeling." || "Cannot be longer than 20 characters.",
            "overallMood": "Please choose a number between 1-10.",
            "iconId": "Please choose an icon.",
            "note": "If you choose to leave a note, it must be longer than 10 characters." || "Note cannot be longer than 255 characters."
        },
      }
      

edit an entry

  • Purpose: Edits a previous entry from a user

  • Require Authentication: true

  • Require proper authorization

  • Request:

    • Method: PUT
    • URL: /api/entries/:entriesId
    • Body:
    {
      "activities": [24, 25, 19],
      "datetime": "2024-09-04 10:22",
      "iconId": 4,
      "levels": [
        { "levelId": 6, "rating": 8 },
        { "levelId": 7, "rating": 8 },
        { "levelId": 8, "rating": 6 },
        { "levelId": 9, "rating": 8 },
        { "levelId": 10, "rating": 8 }
      ],
      "mood": "Determined",
      "note": "I am going to work really hard and get an amazing job!",
      "overallMood": "8"
    }
    
  • Successful Response:

    • Status Code: 200

    • Headers:

      • Content-Type: application/json
    • Body:

      {
      "EntryActivities": [
        { "entryId": 35, "activityId": 19 },
        { "entryId": 35, "activityId": 24 },
        { "entryId": 35, "activityId": 25 }
      ],
      "EntryLevels": [
        { "entryId": 35, "levelId": 6, "rating": 8, "createdAt": "2024-09-04T17:23:35.587Z" },
        { "entryId": 35, "levelId": 7, "rating": 8, "createdAt": "2024-09-04T17:23:35.587Z" },
      ],
      "createdAt": "2024-09-04T17:23:35.570Z",
      "datetime": "2024-09-04T17:22:22.032Z",
      "iconId": 4,
      "id": 35,
      "mood": "Determined",
      "note": "I am going to work really hard and get an amazing job!",
      "overallMood": 8,
      "updatedAt": "2024-09-04T17:23:35.570Z",
      "userId": 4
      }
      
  • Error response: Body validation errors

    • Status Code: 400

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "title": "Validation error",
        "message": "Validation error",
        "errors": {
            "datetime": "Date is required." || "Entry date cannot be in the future." || "Date cannot be before the year 2000.",
            "mood": "Please give a word to describe how you are feeling." || "Cannot be longer than 20 characters.",
            "overallMood": "Please choose a number between 1-10.",
            "iconId": "Please choose an icon.",
            "note": "If you choose to leave a note, it must be longer than 10 characters." || "Note cannot be longer than 255 characters."
        },
      }
      
  • Error response: Entry not found

    • Status Code: 404

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "title": "Not found",
        "message": "Not found",
        "errors": {
            "message": "Entry not found."
        },
      }
      

Delete an entry

  • Purpose: Deletes a previous entry

  • Require Authentication: true

  • Require proper authorization

  • Request:

    • Method: DELETE
    • URL: /api/entries/:entriesId
    • Body: none
  • Successful Response:

    • Status Code: 200

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "message": "Success"
      }
      
  • Error response: Entry not found

    • Status Code: 404

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "title": "Not found",
        "message": "Not found",
        "errors": {
            "message": "Entry not found."
        },
      }
      

Icons

Get all icons

  • Purpose: Returns all icons

  • Require Authentication: true

  • Require proper authorization

  • Request:

    • Method: GET
    • URL: /api/icons
    • Body: none
  • Successful Response:

    • Status Code: 200

    • Headers:

      • Content-Type: application/json
    • Body:

      [
        {
          "createdAt": "2024-09-02T22:42:48.336Z",
          "description": "Laugh beam face",
          "id": 1,
          "name": "FaRegFaceLaughBeam",
          "updatedAt": "2024-09-02T22:42:48.336Z"
        },
      ]
      
  • Error response: Icons not found

    • Status Code: 404

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "title": "Not found",
        "message": "Not found",
        "errors": {
            "message": "Icons not found."
        },
      }
      

Activities

Get all activities

  • Purpose: Returns all activities that belong to a user.

  • Require Authentication: true

  • Require proper authorization

  • Request:

    • Method: GET
    • URL: /api/activities
    • Body: none
  • Successful Response:

    • Status Code: 200
    • Headers:
      • Content-Type: application/json
    • Body:
    [
      {
        "deactivated": false,
        "iconId": 37,
        "id": 25,
        "name": "Work",
        "userId": 4
      }
    ]
    

Create a new activity

  • Purpose: Creates and return a new activity.

  • Require Authentication: true

  • Require proper authorization

  • Request:

    • Method: POST
    • URL: /api/activities
    • Body:
    {
      "iconId": 34,
      "id": undefined,
      "name": "school"
    }
    
  • Successful Response:

    • Status Code: 201
    • Headers:
      • Content-Type: application/json
    • Body:
      {
        "createdAt": "2024-09-04T18:21:06.665Z",
        "deactivated": false,
        "iconId": 34,
        "id": 77,
        "name": "school",
        "updatedAt": "2024-09-04T18:21:06.665Z",
        "userId": 4
      }
    
  • Error response: Body validation errors

    • Status Code: 400

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "title": "Validation error",
      "message": "Validation error",
      "errors": {
          "name": "Please name this activity." || "Activity name must be between 2-30 characters." || "Activity with this name already exists.",
          "iconId": "Please choose an icon to represent this activity."
      },
      }
      

Edit an activity

  • Purpose: Update and returns an activity

  • Require Authentication: true

  • Require proper authorization

  • Request:

    • Method: PUT
    • URL: /api/activities/:activityId
    • Body:
    {
      "iconId": 34,
      "id": 77,
      "name": "school"
    }
    
  • Successful Response:

    • Status Code: 200
    • Headers:
      • Content-Type: application/json
    • Body:
      {
        "deactivated": false,
        "iconId": 34,
        "id": 77,
        "name": "school",
        "userId": 4
      }
    
  • Error response: Body validation errors

    • Status Code: 400

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "title": "Validation error",
      "message": "Validation error",
      "errors": {
          "name": "Please name this activity." || "Activity name must be between 2-30 characters." || "Activity with this name already exists.",
          "iconId": "Please choose an icon to represent this activity."
      },
      }
      
  • Error response: Activity not found

    • Status Code: 404

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "title": "Not found",
        "message": "Not found",
        "errors": {
            "message": "Activity not found."
        },
      }
      

Delete an activity

  • Purpose: Deletes an activity

  • Require Authentication: true

  • Require proper authorization

  • Request:

    • Method: DELETE
    • URL: /api/activities/:activityId
    • Body: none
  • Successful Response:

    • Status Code: 200

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "message": "Success"
      }
      
  • Error response: Activity not found

    • Status Code: 404

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "title": "Not found",
        "message": "Not found",
        "errors": {
            "message": "Activity not found."
        },
      }
      

Levels

Get all levels

  • Purpose: Returns all levels that belong to a user.

  • Require Authentication: true

  • Require proper authorization

  • Request:

    • Method: GET
    • URL: /api/levels
    • Body: none
  • Successful Response:

    • Status Code: 200
    • Headers:
      • Content-Type: application/json
    • Body:
    [
      {
        "color": "#FFEA00",
        "deactivated": false,
        "id": 7,
        "name": "Energy",
        "updatedAt": "2024-09-02T22:42:48.381Z",
        "userId": 4
      },
    ]
    

Create a new level

  • Purpose: Creates and return a new level.

  • Require Authentication: true

  • Require proper authorization

  • Request:

    • Method: POST
    • URL: /api/levels
    • Body:
    {
      "name": "Pain"
    }
    
  • Successful Response:

    • Status Code: 201
    • Headers:
      • Content-Type: application/json
    • Body:
      {
        "createdAt": "2024-09-04T18:21:06.665Z",
        "color": "#FFEA00",
        "deactivated": false,
        "id": 23,
        "name": "pain",
        "updatedAt": "2024-09-02T22:42:48.381Z",
        "userId": 4
      }
    
  • Error response: Body validation errors

    • Status Code: 400

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "title": "Validation error",
        "message": "Validation error",
        "errors": {
            "name": "Please provide a name." || "Level name must between 2 and 15 characters." || "Level with this name already exists."
        },
      }
      

Edit an level

PUT /api/levels/:levelId

  • Purpose: Updates and returns a new level.

  • Require Authentication: true

  • Require proper authorization

  • Request:

    • Method: PUT
    • URL: /api/levels/:levelId
    • Body:
    {
        "color": "#FFEA00",
        "deactivated": false,
        "id": 23,
        "name": "pain",
        "updatedAt": "2024-09-02T22:42:48.381Z",
        "userId": 4
    }
    
  • Error response: Body validation errors

    • Status Code: 400

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "title": "Validation error",
        "message": "Validation error",
        "errors": {
            "name": "Please provide a name." || "Level name must between 2 and 15 characters." || "Level with this name already exists.",
        },
      }
      
  • Successful Response:

    • Status Code: 200
    • Headers:
      • Content-Type: application/json
    • Body:
      {
        "color": "#FFEA00",
        "deactivated": false,
        "id": 23,
        "name": "pain",
        "updatedAt": "2024-09-02T22:42:48.381Z",
        "userId": 4
      }
    
  • Error response: Level not found

    • Status Code: 404

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "title": "Not found",
        "message": "Not found",
        "errors": {
            "message": "Level not found."
        },
      }
      

Delete an level

  • Purpose: Deletes a level

  • Require Authentication: true

  • Require proper authorization

  • Request:

    • Method: DELETE
    • URL: /api/levels/:levelId
    • Body: none
  • Successful Response:

    • Status Code: 200

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "message": "Successful"
      }
      
  • Error response: Level not found

    • Status Code: 404

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "title": "Not found",
        "message": "Not found",
        "errors": {
            "message": "Level not found."
        },
      }