Skip to content

API Docs

Brian Johnson edited this page Feb 13, 2024 · 7 revisions

Byte Bite

Uber Eats Clone Group Project For a/A

USER AUTHENTICATION/AUTHORIZATION

All endpoints that require authentication

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

  • Request: endpoints that require authentication
  • 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. Necessary for a ton of stuff under the hood even if we don't need it for the actual user.

  • Require Authentication: true

  • Request

    • Method: GET
    • URL: /users/:currentUserId
    • 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": "john.smith@gmail.com",
          "username": "JohnSmith"
        }
      }
  • 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: GET

    • URL: /users/login

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "credential": "john.smith@gmail.com",
        "password": "secret password"
      }
  • Successful Response

    • Status Code: 200

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "user": {
          "id": 1,
          "firstName": "John",
          "lastName": "Smith",
          "email": "john.smith@gmail.com",
          "username": "JohnSmith"
        }
      }
  • 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",
        "errors": {
          "credential": "Email or username is 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: users/

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "firstName": "John",
        "lastName": "Smith",
        "email": "john.smith@gmail.com",
        "username": "JohnSmith",
        "password": "secret password"
      }
  • Successful Response

    • Status Code: 200

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "user": {
          "id": 1,
          "firstName": "John",
          "lastName": "Smith",
          "email": "john.smith@gmail.com",
          "username": "JohnSmith"
        }
      }
  • 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: User already exists with the specified username

    • Status Code: 500

    • Headers:

      • Content-Type: application/json
    • Body:

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

    • Status Code: 400

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "message": "Bad Request",
        "errors": {
          "email": "Invalid email",
          "username": "Username is required",
          "firstName": "First Name is required",
          "lastName": "Last Name is required"
        }
      }

      RESTAURANTS

      GET ALL RESTAURANTS BY DELIVERY

      Every restaurant has a Delivery boolean which indicates whether they deliver or not, this route shows a list of all restaurants which can deliver.

      • Require Authentication: false
      • Request
        • Method: GET

        • URL: /restaurants/

        • Body:

          {
            "Restaurants":
              [{
              "id": "1",
              "name": "McDonald's",
              "address": "123 Fake St",
              "image": "image.url",
              "categoryId": 1,
              "starRating": 4.5,
              },
              {
              "id": "2",
              "name": "Taco Bell",
              "address": "345 Fake St",
              "image": "image.url",
              "categoryId": 1,
              "starRating": 4.5
              }]
          
          }

GET RESTAURANT DETAILS BY RESTAURANT ID

Returns the details of a restaurant including MenuItems

  • Require Authentication: false

  • Request

    • Method: GET
    • URL: /restaurants/:restaurantId
    • Body: none
  • Successful Response

    • Status Code: 200
    • Headers:
      • Content-Type: application/json
    • Body:
      {
        "id": 1,
        "ownerId": 1,
        "address": "123 Fake St",
        "city": "San Francisco",
        "state": "California",
        "lat": 37.7645358,
        "lng": -122.4730327,
        "name": "McDonald's",
        "categoryId": 1,
        "delivery": true,
        "createdAt": "2021-11-19 20:39:36",
        "updatedAt": "2021-11-19 20:39:36" ,
        "numReviews": 5,
        "avgStarRating": 4.5,
        "MenuItems": [
          {
            "id": 1,
            "name": "fries",
            "price": 1.00
          },
          {
            "id": 2,
            "name": "burger",
            "price": 4.99        }
        ],
        "Owner": {
          "id": 1,
          "firstName": "John",
          "lastName": "Smith"
        }
      }
  • Error response: Couldn't find a restaurant with the specified id

    • Status Code: 404

    • Headers:

      • Content-Type: application/json
    • Body:

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

CREATE A RESTAURANT

Creates and returns a new restaurant.

  • Require Authentication: true

  • Request

    • Method: POST

    • URL: /restaurants/

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "address": "123 Fake St",
        "city": "San Francisco",
        "state": "California",
        "image": "image/url.jpg",
        "lat": 37.7645358,
        "lng": -122.4730327,
        "name": "mcDonald's",
        "categoryId": 1,
        "devliery": true
      }
  • Successful Response

    • Status Code: 201

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "id": 1,
        "ownerId": 1,
        "address": "123 Fake St",
        "city": "San Francisco",
        "state": "California",
        "country": "United States of America",
        "lat": 37.7645358,
        "lng": -122.4730327,
        "name": "McDonald's",
        "categoryId": 1,
        "delivers": true,
        "createdAt": "2021-11-19 20:39:36",
        "updatedAt": "2021-11-19 20:39:36"
      }
  • Error Response: Body validation error

    • Status Code: 400

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "message": "Bad Request",
        "errors": {
          "address": "Street address is required",
          "city": "City is required",
          "state": "State is required",
          "country": "Country is required",
          "lat": "Latitude is not valid",
          "lng": "Longitude is not valid",
          "name": "Name must be less than 50 characters",
          "categoryId": 1,
          "delivers": "delivery status is required"
        }
      }

EDIT A RESTAURANT

Updates and returns an existing restaurant.

  • Require Authentication: true

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

  • Request

    • Method: PUT

    • URL: /restaurants/:restaurantId

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "address": "123 Fake St",
        "city": "San Francisco",
        "state": "California",
        "image": "image/url.jpg"
        "lat": 37.7645358,
        "lng": -122.4730327,
        "name": "McDonald's",
        "categoryId": 1,
        "delivery": true
      }
  • Successful Response

    • Status Code: 200

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "id": 1,
        "ownerId": 1,
        "address": "123 Fake St",
        "city": "San Francisco",
        "state": "California",
        "image": "image/url.jpg",
        "lat": 37.7645358,
        "lng": -122.4730327,
        "name": "McDonald's",
        "categoryId": 1,
        "delivery": true,
        "createdAt": "2021-11-19 20:39:36",
        "updatedAt": "2021-11-20 10:06:40"
      }
  • Error Response: Body validation error

    • Status Code: 400

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "message": "Bad Request",
        "errors": {
          "address": "Street address is required",
          "city": "City is required",
          "state": "State is required",
          "image": "image/url.jpg",
          "lat": "Latitude is not valid",
          "lng": "Longitude is not valid",
          "name": "Name must be less than 50 characters",
           "categoryId": 1,
          "delivers": "delivery status is required"
        }
      }
  • Error response: Couldn't find a restaurant with the specified id

    • Status Code: 404

    • Headers:

      • Content-Type: application/json
    • Body:

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

Delete a restaurant

Deletes an existing restaurant.

  • Require Authentication: true

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

  • Request

    • Method: DELETE
    • URL: /restaurants/:restaurantId
    • Body: none
  • Successful Response

    • Status Code: 200

    • Headers:

      • Content-Type: application/json
    • Body:

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

    • Status Code: 404

    • Headers:

      • Content-Type: application/json
    • Body:

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

      MENU ITEMS

      Get Menu Item Details By Id

      • Authentication: false

      • Authorization: false

      • Request

        • Method: GET
        • Res
        {
         "id": 1,
         "name": "burger",
         "description": "a juicy burger",
         "price": 4.99,
         "resaturantId": 1
        }
        
      • Error response: Couldn't find a Menu Item with the specified id

      • Status Code: 404

      • Headers:

      • Content-Type: application/json

      • Body:

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

      Create a Menu Item

      Add a menu item to an existing restaurant that the current user owns.

      • Require Authentication: true
      • Require proper authorization: restaurant that menu item belongs to must belong to the current user
      • Request
        • Method: POST
        • URL: /restaurants/:restaurant_id/menu_items/
        • Headers:
        • Content-Type: application/json
      • Body:
      {
        "restaurant_id": 1,
        "name": "burger",
        "image": "burgers.com/juicy.jpg",
        "price": 4.99
      }
      • Successful Response
        • Status Code: 200
        • Headers:
        • Content-Type: application/json
        • Body:
      {
        "id": 1,
        "restaurant_id": 1,
        "name": "burger",
        "image": "burgers.com/juicy.jpg",
        "price": 4.99
      }
      • Error response: Couldn't find a restaurant with the specified id
    • Status Code: 404

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "message": "restaurant couldn't be found"
      }
      • Error response: Validation errors on menu item
    • Status Code: 400

    • Headers:

      • Content-Type: application/json
    • Body:

       {
        "errors": {
        "name": "Name is required",
        "price": "Price is required"}
      }

      Edit Menu Item

      Edit a menu item.

  • Require Authentication: true

  • Require proper authorization: restaurant that menu item belongs to must belong to the current user

  • Request

    • Method: PUT

    • URL: /restaurants/:restaurant_id/menu_items/:menu_item_id

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "id": 1,
        "restaurant_id": 1,
        "name": "burger",
        "image": "burgers.com/juicy.jpg",
        "price": 3.99
      }
  • Successful Response

    • Status Code: 200

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "id": 1,
        "restaurant_id": 1,
        "name": "burger",
        "image": "burgers.com/juicy.jpg",
        "price": 3.99
      }
  • Error response: Couldn't find a restaurant with the specified id

    • Status Code: 404

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "message": "restaurant couldn't be found"
      }
  • Error response: Couldn't find a menu item with the specified id

    • Status Code: 404

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "message": "Menu Item couldn't be found"
      }

Delete a Menu Item

Deletes an existing Menu Item.

  • Require Authentication: true

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

  • Request

    • Method: DELETE
    • URL: restaurants/:restaurant_id/menu_items/:menu_item_id
    • Body: none
  • Successful Response

    • Status Code: 200

    • Headers:

      • Content-Type: application/json
    • Body:

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

    • Status Code: 404

    • Headers:

      • Content-Type: application/json
    • Body:

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

REVIEWS

Get all Reviews of the Current User

Returns all the reviews written by the current user. Cannot review own restaurant

  • Require Authentication: true

  • Request

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

    • Status Code: 200

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "Reviews": [
          {
            "id": 1,
            "userId": 2,
            "restaurantId": 1,
            "review": "This was an awesome restaurant!",
            "stars": 5,
            "createdAt": "2021-11-19 20:39:36",
            "updatedAt": "2021-11-19 20:39:36" ,
            "User": {
              "id": 2,
              "firstName": "Ron",
              "lastName": "McDon"
            },
            "restaurant": {
              "id": 1,
              "ownerId": 1,
              "address": "123 Fake St",
              "city": "San Francisco",
              "state": "California",
              "country": "United States of America",
              "lat": 37.7645358,
              "lng": -122.4730327,
              "name": "McDonald's",
              "categoryId": 1,
              "delivers": true,
            },
            "ReviewImages": [
              {
                "id": 1,
                "url": "image url"
              }
            ]
          }
        ]
      }

Get all Reviews by a restaurant's id

Returns all the reviews that belong to a restaurant specified by id.

  • Require Authentication: false

  • Request

    • Method: GET
    • URL: /restaurants/:restaurantId/reviews
    • Body: none
  • Successful Response

    • Status Code: 200

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "Reviews": [
          {
            "id": 1,
            "userId": 1,
            "restaurantId": 1,
            "review": "This was an awesome restaurant!",
            "stars": 5,
            "createdAt": "2021-11-19 20:39:36",
            "updatedAt": "2021-11-19 20:39:36" ,
            "User": {
              "id": 1,
              "firstName": "John",
              "lastName": "Smith"
            },
          }
        ]
      }
  • Error response: Couldn't find a restaurant with the specified id

    • Status Code: 404

    • Headers:

      • Content-Type: application/json
    • Body:

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

Create a Review for a restaurant based on the restaurant's id

Create and return a new review for a restaurant specified by id.

  • Require Authentication: true

  • Request

    • Method: POST

    • URL: restaurants/:restaurantId/reviews

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "review": "This was an awesome restaurant!",
        "stars": 5,
      }
  • Successful Response

    • Status Code: 201

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "id": 1,
        "userId": 1,
        "restaurantId": 1,
        "review": "This was an awesome restaurant!",
        "stars": 5,
        "createdAt": "2021-11-19 20:39:36",
        "updatedAt": "2021-11-19 20:39:36"
      }
  • Error Response: Body validation errors

    • Status Code: 400

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "message": "Bad Request",
        "errors": {
          "review": "Review text is required",
          "stars": "Stars must be an integer from 1 to 5",
        }
      }
  • Error response: Couldn't find a restaurant with the specified id

    • Status Code: 404

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "message": "restaurant couldn't be found"
      }
  • Error response: Review from the current user already exists for the restaurant

    • Status Code: 500

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "message": "User already has a review for this restaurant"
      }

Edit a Review

Update and return an existing review.

  • Require Authentication: true

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

  • Request

    • Method: PUT

    • URL: reviews/:reviewId

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "review": "This was an awesome restaurant!",
        "stars": 5,
      }
  • Successful Response

    • Status Code: 200

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "id": 1,
        "userId": 1,
        "restaurantId": 1,
        "review": "This was an awesome restaurant!",
        "stars": 5,
        "createdAt": "2021-11-19 20:39:36",
        "updatedAt": "2021-11-20 10:06:40"
      }
  • Error Response: Body validation errors

    • Status Code: 400

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "message": "Bad Request",
        "errors": {
          "review": "Review text is required",
          "stars": "Stars must be an integer from 1 to 5",
        }
      }
  • Error response: Couldn't find a Review with the specified id

    • Status Code: 404

    • Headers:

      • Content-Type: application/json
    • Body:

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

Delete a Review

Delete an existing review.

  • Require Authentication: true

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

  • Request

    • Method: DELETE
    • URL: /reviews/:reviewId
    • Body: none
  • Successful Response

    • Status Code: 200

    • Headers:

      • Content-Type: application/json
    • Body:

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

    • Status Code: 404

    • Headers:

      • Content-Type: application/json
    • Body:

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

ORDERS

Get all of the Current User's Order History

Return all the orders that the current user has made.

  • Require Authentication: true

  • Request

    • Method: GET
    • URL: api/users/:currentUserId/orders
    • Body: none
  • Successful Response

    • Status Code: 200

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "orders": [
          {
            "id": 1,
            "restaurant": {
              "id": 1,
              "name": "McDonald's",
            },
            "customer": 2,
            "createdAt": "2021-11-19 20:39:36",
            "updatedAt": "2021-11-19 20:39:36"
          }
        ]
      }

Get details of an Order by id

Return the details of an order with the correct ID

  • Require Authorization: true

  • Require Authentication: true

  • Request

    • Method: GET
    • URL: api/orders/:orderId
    • Body: none
  • Successful Response:

    • Status Code: 200

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "orders": [
          {
            "User": {
              "id": 2,
              "firstName": "John",
              "lastName": "Smith"
            },
            "Menu Items": [
              {
              "id": 1,
              "restaurant_id": 1,
              "name": "burger",
              "image": "burgers.com/juicy.jpg",
              "price": 3.99
             },
             {
              "id": 2,
              "restaurant_id": 1,
              "name": "fries",
              "image": "burgers.com/juicy.jpg",
              "price": 1.00
              },
            ],
            "id": 1,
            "restaurant_id": 1,
            "customer": 2,
            "status": "Out for Delivery",
            "price": 4.99,
            "createdAt": "2021-11-19 20:39:36",
            "updatedAt": "2021-11-19 20:39:36"
          }
        ]
      }
  • Error response: Couldn't find a restaurant with the specified id

    • Status Code: 404

    • Headers:

      • Content-Type: application/json
    • Body:

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

Submit an Order

Create a new Byte Bite order.

  • Require Authentication: true

  • Require proper authorization: restaurant must NOT belong to the current user

  • Request

    • Method: POST

    • URL: api/orders/

    • Body:

          { "menu_items": [
              {
              "menu_item_id": 1,
              "quantity": 1
             },
             {
              "menu_item_id": 1,
              "quantity": 1
             },
            ],
            "id": 1,
            "restaurant_id": 1,
            "user_id": 2,
            "price": 4.99,
          }
  • Successful Response

    • Status Code: 200

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "id": 1,
        "restaurant_id": 1,
        "user_id": 2,
        "driver": "Jimmy",
        "status": "created",
        "createdAt": "2021-11-19 20:39:36",
        "updatedAt": "2021-11-19 20:39:36"
      }
  • Error response: Restaurant not found

    • Status Code: 404

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "error": "Could not find a restaurant by that id"
      }
  • Error response: Couldn't find a menu item with the specified id

    • Status Code: 404

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "error": "Menu item could not be found"
      }

Delete an Order

Remove an order from order history.

  • Require Authentication: true

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

  • Request

    • Method: DELETE
    • URL: users/:currentUserId/orders/:orderId
    • Headers:
      • Content-Type: application/json
  • Successful Response

    • Status Code: 200

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "msg":"Successfully Deleted"
      }
  • Error response: Couldn't find a Order with the specified id

    • Status Code: 404

    • Headers:

      • Content-Type: application/json
    • Body:

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

Cancel a Order

Cancel an existing order.

  • Require Authentication: true

  • Require proper authorization: Order must belong to the current user or the restaurant must belong to the current user

  • Request

    • Method: DELETE
    • URL: /users/:currentUserId/orders/:order_id
    • Body: none
  • Successful Response

    • Status Code: 200

    • Headers:

      • Content-Type: application/json
    • Body:

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

    • Status Code: 404

    • Headers:

      • Content-Type: application/json
    • Body:

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