Skip to content

API Documentation

Daniel Valdecantos edited this page Jul 11, 2023 · 2 revisions

USER AUTHENTICATION/AUTHORIZATION

All endpoints that require authentication

All endpoints that require a current user to be logged in.

  • Request: endpoints that require authentication (all)

  • Error Response: Require authentication

    • Status Code: 401

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "message": "Authentication required"
      }

All endpoints that require proper authorization

All endpoints that require authentication and the current user does not have the correct role(s) or permission(s).

  • Request: endpoints that require proper authorization

  • Error Response: Require proper authorization

    • Status Code: 403

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "message": "Forbidden"
      }

Get the Current User

Returns the information about the current user that is logged in.

  • Require Authentication: true

  • Request

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

    • Status Code: 200

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "user": {
          "id": 1,
          "name": "dani buva",
          "email": "danibuva@gmail.com",
        }
      }
  • Successful Response when there is no logged in user

    • Status Code: 200

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "user": null
      }

Log In a User

Logs in a current user with valid credentials and returns the current user's information.

  • Require Authentication: false

  • Request

    • Method: POST

    • URL: /api/auth

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "email": "danibuva@gmail.com",
        "password": "password"
      }
  • Successful Response

    • Status Code: 200

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "user": {
          "id": 1,
          "name": "dani buva",
          "email": "danibuva@gmail.com",
        }
      }
  • Error Response: Invalid credentials

    • Status Code: 401

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "message": "Invalid credentials"
      }
  • 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": {
          "email": "email required",
          "password": "password is required"
        }
      }

Sign Up a User

Creates a new user, logs them in as the current user, and returns the current user's information.

  • Require Authentication: false

  • Request

    • Method: POST

    • URL: /api/auth

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "name": "danibuva",
        "email": "danibuva@gmail.com",
        "password": "password",
        "focus": ["work", "friend"]
      }
  • Successful Response

    • Status Code: 200

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "user": {
          "id": 1,
          "name": "dani",
          "email": "danibuva@gmail.com",
          "focus": ["work", "friend"]
        }
      }
  • Error response: User already exists with the specified email

    • Status Code: 500

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "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:

      {
        "message": "Bad Request", // (or "Validation error" if generated by Sequelize),
        "errors": {
          "email": "invalid email",
          "name": "name is required"
        }
      }

Entries

  • all entry endpoints require current user to be logged in and own the entry

Get all Entries

Returns all the current user's journal entries.

  • Require Authentication: true

  • Request

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

    • Status Code: 200

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "entries": [
          {
            "id": 1,
            "userId": 1,
            "sleep": 4,
            "motivation": 4,
            "focus": "love",
            "body": "How would your day look like, if you were to only do activities that make you feel happy and fulfilled? \n <answer>",
            "conclusion": "What do you have in life now that you did't have a year ago? \n <answer>",
            "prepared": false
          }
        ]
      }

Get details of a Morning Check in from an id

Returns the details of a spot specified by its id.

  • Require Authentication: true

  • Require Authorization: must be the user who owns the morning reflection

  • Request

    • Method: GET
    • URL: /api/journey/day/:id
    • Body: none
  • Successful Response

    • Status Code: 200

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "id": 1,
        "userId": 1,
        "sleep": 4,
        "motivation": 4,
        "focus": "love",
        "body": "How would your day look like, if you were to only do activities that make you feel happy and fulfilled? \n <answer>",
        "conclusion": "What do you have in life now that you did't have a year ago? \n <answer>",
        "prepared": false
      }
  • Error response: Couldn't find a Check in with the specified id

    • Status Code: 404

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "message": "check in not found"
      }

Get details of a Evening Check in from an id

Returns the details of a spot specified by its id.

  • Require Authentication: true

  • Require Authorization: must be the user who owns the evening reflection

  • Request

    • Method: GET
    • URL: /api/journey/night/:id
    • Body: none
  • Successful Response

    • Status Code: 200

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "id": 1,
        "userId": 1,
        "rest": 4,
        "stress": 4,
        "productivity": 3,
        "feeling": "happy",
        "body": "How would your day look like, if you were to only do activities that make you feel happy and fulfilled? \n <answer>",
        "conclusion": "What do you have in life now that you did't have a year ago? \n <answer>",
        "prepared": false
      }
  • Error response: Couldn't find a Check in with the specified id

    • Status Code: 404

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "message": "check in not found"
      }

Get details of a Mood Check in from an id

Returns the details of a spot specified by its id.

  • Require Authentication: true

  • Require Authorization: must be the user who owns the morning reflection

  • Request

    • Method: GET
    • URL: /api/journey/mood/:id
    • Body: none
  • Successful Response

    • Status Code: 200

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "id": 1,
        "feeling": 4,
        "description": "calm",
        "origin": "date",
        "body": "Why do you think <origin> is making you feel this way? \n <answer>",
        "conclusion": "What do you have in life now that you did't have a year ago? \n <answer>",
        "prepared": false
      }
  • Error response: Couldn't find a Check in with the specified id

    • Status Code: 404

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "message": "check in not found"
      }

Create a Morning Reflection

Creates and returns a new morning check in/ reflection.

  • Require Authentication: true

  • Request

    • Method: POST

    • URL: /api/journey/day

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "sleep": 3,
        "motivation": 2,
        "focus": "Relaxing",
        "body": "How would your day look like, if you were to only do activities that make you feel happy and fulfilled? \n <answer>",
        "conclusion": "What do you have in life now that you did't have a year ago? \n <answer>",
        "prepared": false
      }
  • Successful Response

    • Status Code: 201

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "id": 1,
        "sleep": 4,
        "motivation": 4,
        "focus": "love",
        "body": "How would your day look like, if you were to only do activities that make you feel happy and fulfilled? \n <answer>",
        "conclusion": "What do you have in life now that you did't have a year ago? \n <answer>",
        "prepared": false
      }
  • Error Response: Body validation error

    • Status Code: 400

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "message": "Bad Request", // (or "Validation error" if generated by Sequelize),
        "errors": {
          "sleep": "sleep is required",
          "motivation": "motivation is required",
          "focus": "focus is required",
          "body": "body is required",
          "conclusion": "conclusion is required",
          "prepared": "prepared is required"
        }
      }

Create a Evening Reflection

Creates and returns a new evening check in/ reflection.

  • Require Authentication: true

  • Request

    • Method: POST

    • URL: /api/journey/night

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "rest": 3,
        "stress": 2,
        "productivity": 3,
        "feeling": "Calm",
        "origin": "Learning",
        "summary": "I studied a lot today and feel content with the amount I learned. Now I am just chilling.",
        "prepared": false
      }
  • Successful Response

    • Status Code: 201

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "id": 1,
        "rest": 3,
        "stress": 2,
        "productivity": 3,
        "feeling": "Calm",
        "origin": "Learning",
        "summary": "I studied a lot today and feel content with the amount I learned. Now I am just chilling.",
        "prepared": false
      }
  • Error Response: Body validation error

    • Status Code: 400

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "message": "Bad Request", // (or "Validation error" if generated by Sequelize),
        "errors": {
          "rest": "rest is required",
          "stress": "stress is required",
          "productivity": "productivity is required",
          "feeling": "feeling is required",
          "origin": "origin is required",
          "summary": "summary is required",
          "prepared": "prepared is required"
        }
      }

Create a Mood check in

Creates and returns a new mood check in/ entry.

  • Require Authentication: true

  • Request

    • Method: POST

    • URL: /api/journey/mood

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "feeling": 2,
        "type": "Angry",
        "origin": "Friends",
        "body": "My friends don't treat me how I want to be treated :/",
        "conclusion": "Is there something you need to make amends to? \n <answer>",
      }
  • Successful Response

    • Status Code: 201

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "id": 1,
        "feeling": 2,
        "type": "Angry",
        "origin": "Friends",
        "body": "My friends don't treat me how I want to be treated :/",
        "conclusion": "Is there something you need to make amends to? \n <answer>",
      }
  • Error Response: Body validation error

    • Status Code: 400

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "message": "Bad Request", // (or "Validation error" if generated by Sequelize),
        "errors": {
          "feeling": "feeling is required",
          "type": "type is required",
          "origin": "origin is required",
          "body": "body is required",
          "conclusion": "conclusion is required",
        }
      }

Edit a Morning reflection

Updates and returns an existing morning reflection.

  • Require Authentication: true

  • Require proper authorization: morning reflection must belong to the current user

  • Request

    • Method: PUT

    • URL: /api/journey/day/:id

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "sleep": 3,
        "motivation": 2,
        "focus": "Relaxing",
        "body": "How would your day look like, if you were to only do activities that make you feel happy and fulfilled? \n <answer>",
        "conclusion": "What do you have in life now that you did't have a year ago? \n <answer>",
        "prepared": false
      }
  • Successful Response

    • Status Code: 200

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "id": 1,
        "sleep": 4,
        "motivation": 4,
        "focus": "love",
        "body": "How would your day look like, if you were to only do activities that make you feel happy and fulfilled? \n <answer>",
        "conclusion": "What do you have in life now that you did't have a year ago? \n <answer>",
        "prepared": false
      }
  • Error Response: Body validation error

    • Status Code: 400

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "message": "Bad Request", // (or "Validation error" if generated by Sequelize),
        "errors": {
          "sleep": "sleep is required",
          "motivation": "motivation is required",
          "focus": "focus is required",
          "body": "body is required",
          "conclusion": "conclusion is required",
          "prepared": "prepared is required"
        }
      }
  • Error response: Couldn't find a Morning check in with the specified id

    • Status Code: 404

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "message": "check in not found"
      }

Edit an Evening reflection

Updates and returns an existing evening reflection.

  • Require Authentication: true

  • Require proper authorization: evening reflection must belong to the current user

  • Request

    • Method: PUT

    • URL: /api/journey/night/:id

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "rest": 3,
        "stress": 2,
        "productivity": 3,
        "feeling": "Calm",
        "origin": "Learning",
        "summary": "I studied a lot today and feel content with the amount I learned. Now I am just chilling.",
        "prepared": false
      }
  • Successful Response

    • Status Code: 201

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "id": 1,
        "rest": 3,
        "stress": 2,
        "productivity": 3,
        "feeling": "Calm",
        "origin": "Learning",
        "summary": "I studied a lot today and feel content with the amount I learned. Now I am just chilling.",
        "prepared": false
      }
  • Error Response: Body validation error

    • Status Code: 400

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "message": "Bad Request", // (or "Validation error" if generated by Sequelize),
        "errors": {
          "rest": "rest is required",
          "stress": "stress is required",
          "productivity": "productivity is required",
          "feeling": "feeling is required",
          "origin": "origin is required",
          "summary": "summary is required",
          "prepared": "prepared is required"
        }
      }
  • Error response: Couldn't find an Evening check in with the specified id

    • Status Code: 404

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "message": "check in not found"
      }

Edit a Mood check in

Updates and returns an existing mood check in.

  • Require Authentication: true

  • Require proper authorization: mood check in must belong to the current user

  • Request

    • Method: PUT

    • URL: /api/journey/mood/:id

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "feeling": 2,
        "type": "Angry",
        "origin": "Friends",
        "body": "My friends don't treat me how I want to be treated :/",
        "conclusion": "Is there something you need to make amends to? \n <answer>",
      }
  • Successful Response

    • Status Code: 201

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "id": 1,
        "feeling": 2,
        "type": "Angry",
        "origin": "Friends",
        "body": "My friends don't treat me how I want to be treated :/",
        "conclusion": "Is there something you need to make amends to? \n <answer>",
      }
  • Error Response: Body validation error

    • Status Code: 400

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "message": "Bad Request", // (or "Validation error" if generated by Sequelize),
        "errors": {
          "feeling": "feeling is required",
          "type": "type is required",
          "origin": "origin is required",
          "body": "body is required",
          "conclusion": "conclusion is required",
        }
      }
  • Error response: Couldn't find an Mood check in with the specified id

    • Status Code: 404

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "message": "check in not found"
      }

Delete a Morning Reflection

Deletes an existing Morning Reflection.

  • Require Authentication: true

  • Require proper authorization: Morning Reflection must belong to the current user

  • Request

    • Method: DELETE
    • URL: /api/journey/day/:id
    • Body: none
  • Successful Response

    • Status Code: 200

    • Headers:

      • Content-Type: application/json
    • Body:

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

    • Status Code: 404

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "message": "Check in not found"
      }

Delete an Evening Reflection

Deletes an existing Evening Reflection.

  • Require Authentication: true

  • Require proper authorization: Evening Reflection must belong to the current user

  • Request

    • Method: DELETE
    • URL: /api/journey/night/:id
    • Body: none
  • Successful Response

    • Status Code: 200

    • Headers:

      • Content-Type: application/json
    • Body:

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

    • Status Code: 404

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "message": "Check in not found"
      }

Delete a Mood Check in

Deletes an existing Mood Check in.

  • Require Authentication: true

  • Require proper authorization: Mood check in must belong to the current user

  • Request

    • Method: DELETE
    • URL: /api/journey/mood/:id
    • Body: none
  • Successful Response

    • Status Code: 200

    • Headers:

      • Content-Type: application/json
    • Body:

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

    • Status Code: 404

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "message": "Check in not found"
      }