Coder Social home page Coder Social logo

airbnb's Introduction

AirBnB Clone

Database Schema Design

SCHEMA

API Documentation

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",
        "statusCode": 401
      }

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",
        "statusCode": 403
      }

Get the Current User

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

  • Require Authentication: true

  • Request

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

    • Status Code: 200

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "user": {
          "id": 1,
          "firstName": "John",
          "lastName": "Smith",
          "email": "[email protected]",
          "username": "JohnSmith"
        }
      }

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/session

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "credential": "[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]",
          "username": "JohnSmith"
        }
      }
  • Error Response: Invalid credentials

    • Status Code: 401

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "message": "Invalid credentials",
        "statusCode": 401
      }
  • Error response: Body validation errors

    • Status Code: 400

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "message": "Validation error",
        "statusCode": 400,
        "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: /api/users

    • Headers:

      • Content-Type: application/json
    • Body:

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

    • Status Code: 200

    • Headers:

      • Content-Type: application/json
    • Body:

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

    • Status Code: 403

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "message": "User already exists",
        "statusCode": 403,
        "errors": {
          "email": "User with that email already exists"
        }
      }
  • Error response: User already exists with the specified username

    • Status Code: 403

    • Headers:

      • Content-Type: application/json
    • Body:

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

    • Status Code: 400

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "message": "Validation error",
        "statusCode": 400,
        "errors": {
          "email": "Invalid email",
          "username": "Username is required",
          "firstName": "First Name is required",
          "lastName": "Last Name is required"
        }
      }

SPOTS

Get all Spots

Returns all the spots.

  • Require Authentication: false

  • Request

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

    • Status Code: 200

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "Spots": [
          {
            "id": 1,
            "ownerId": 1,
            "address": "123 Disney Lane",
            "city": "San Francisco",
            "state": "California",
            "country": "United States of America",
            "lat": 37.7645358,
            "lng": -122.4730327,
            "name": "App Academy",
            "description": "Place where web developers are created",
            "price": 123,
            "createdAt": "2021-11-19 20:39:36",
            "updatedAt": "2021-11-19 20:39:36",
            "avgRating": 4.5,
            "previewImage": "image url"
          }
        ]
      }

Get all Spots owned by the Current User

Returns all the spots owned (created) by the current user.

  • Require Authentication: true

  • Request

    • Method: GET
    • URL: /api/spots/current
    • Body: none
  • Successful Response

    • Status Code: 200

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "Spots": [
          {
            "id": 1,
            "ownerId": 1,
            "address": "123 Disney Lane",
            "city": "San Francisco",
            "state": "California",
            "country": "United States of America",
            "lat": 37.7645358,
            "lng": -122.4730327,
            "name": "App Academy",
            "description": "Place where web developers are created",
            "price": 123,
            "createdAt": "2021-11-19 20:39:36",
            "updatedAt": "2021-11-19 20:39:36",
            "avgRating": 4.5,
            "previewImage": "image url"
          }
        ]
      }

Get details of a Spot from an id

Returns the details of a spot specified by its id.

  • Require Authentication: false

  • Request

    • Method: GET
    • URL: /api/spots/:spotId
    • Body: none
  • Successful Response

    • Status Code: 200

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "id": 1,
        "ownerId": 1,
        "address": "123 Disney Lane",
        "city": "San Francisco",
        "state": "California",
        "country": "United States of America",
        "lat": 37.7645358,
        "lng": -122.4730327,
        "name": "App Academy",
        "description": "Place where web developers are created",
        "price": 123,
        "createdAt": "2021-11-19 20:39:36",
        "updatedAt": "2021-11-19 20:39:36",
        "numReviews": 5,
        "avgStarRating": 4.5,
        "SpotImages": [
          {
            "id": 1,
            "url": "image url",
            "preview": true
          },
          {
            "id": 2,
            "url": "image url",
            "preview": false
          }
        ],
        "Owner": {
          "id": 1,
          "firstName": "John",
          "lastName": "Smith"
        }
      }
  • Error response: Couldn't find a Spot with the specified id

    • Status Code: 404

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "message": "Spot couldn't be found",
        "statusCode": 404
      }

Create a Spot

Creates and returns a new spot.

  • Require Authentication: true

  • Request

    • Method: POST

    • URL: /api/spots

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "address": "123 Disney Lane",
        "city": "San Francisco",
        "state": "California",
        "country": "United States of America",
        "lat": 37.7645358,
        "lng": -122.4730327,
        "name": "App Academy",
        "description": "Place where web developers are created",
        "price": 123
      }
  • Successful Response

    • Status Code: 201

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "id": 1,
        "ownerId": 1,
        "address": "123 Disney Lane",
        "city": "San Francisco",
        "state": "California",
        "country": "United States of America",
        "lat": 37.7645358,
        "lng": -122.4730327,
        "name": "App Academy",
        "description": "Place where web developers are created",
        "price": 123,
        "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": "Validation Error",
        "statusCode": 400,
        "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",
          "description": "Description is required",
          "price": "Price per day is required"
        }
      }

Add an Image to a Spot based on the Spot's id

Create and return a new image for a spot specified by id.

  • Require Authentication: true

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

  • Request

    • Method: POST

    • URL: /api/spots/:spotId/images

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "url": "image url",
        "preview": true
      }
  • Successful Response

    • Status Code: 200

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "id": 1,
        "url": "image url",
        "preview": true
      }
  • Error response: Couldn't find a Spot with the specified id

    • Status Code: 404

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "message": "Spot couldn't be found",
        "statusCode": 404
      }

Edit a Spot

Updates and returns an existing spot.

  • Require Authentication: true

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

  • Request

    • Method: PUT

    • URL: /api/spots/:spotId

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "address": "123 Disney Lane",
        "city": "San Francisco",
        "state": "California",
        "country": "United States of America",
        "lat": 37.7645358,
        "lng": -122.4730327,
        "name": "App Academy",
        "description": "Place where web developers are created",
        "price": 123
      }
  • Successful Response

    • Status Code: 200

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "id": 1,
        "ownerId": 1,
        "address": "123 Disney Lane",
        "city": "San Francisco",
        "state": "California",
        "country": "United States of America",
        "lat": 37.7645358,
        "lng": -122.4730327,
        "name": "App Academy",
        "description": "Place where web developers are created",
        "price": 123,
        "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": "Validation Error",
        "statusCode": 400,
        "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",
          "description": "Description is required",
          "price": "Price per day is required"
        }
      }
  • Error response: Couldn't find a Spot with the specified id

    • Status Code: 404

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "message": "Spot couldn't be found",
        "statusCode": 404
      }

Delete a Spot

Deletes an existing spot.

  • Require Authentication: true

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

  • Request

    • Method: DELETE
    • URL: /api/spots/:spotId
    • Body: none
  • Successful Response

    • Status Code: 200

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "message": "Successfully deleted",
        "statusCode": 200
      }
  • Error response: Couldn't find a Spot with the specified id

    • Status Code: 404

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "message": "Spot couldn't be found",
        "statusCode": 404
      }

REVIEWS

Get all Reviews of the Current User

Returns all the reviews written by the current user.

  • Require Authentication: true

  • Request

    • Method: GET
    • URL: /api/reviews/current
    • Body: none
  • Successful Response

    • Status Code: 200

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "Reviews": [
          {
            "id": 1,
            "userId": 1,
            "spotId": 1,
            "review": "This was an awesome spot!",
            "stars": 5,
            "createdAt": "2021-11-19 20:39:36",
            "updatedAt": "2021-11-19 20:39:36",
            "User": {
              "id": 1,
              "firstName": "John",
              "lastName": "Smith"
            },
            "Spot": {
              "id": 1,
              "ownerId": 1,
              "address": "123 Disney Lane",
              "city": "San Francisco",
              "state": "California",
              "country": "United States of America",
              "lat": 37.7645358,
              "lng": -122.4730327,
              "name": "App Academy",
              "price": 123,
              "previewImage": "image url"
            },
            "ReviewImages": [
              {
                "id": 1,
                "url": "image url"
              }
            ]
          }
        ]
      }

Get all Reviews by a Spot's id

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

  • Require Authentication: false

  • Request

    • Method: GET
    • URL: /api/spots/:spotId/reviews
    • Body: none
  • Successful Response

    • Status Code: 200

    • Headers:

      • Content-Type: application/json
    • Body:

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

    • Status Code: 404

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "message": "Spot couldn't be found",
        "statusCode": 404
      }

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

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

  • Require Authentication: true

  • Request

    • Method: POST

    • URL: /api/spots/:spotId/reviews

    • Headers:

      • Content-Type: application/json
    • Body:

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

    • Status Code: 201

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "id": 1,
        "userId": 1,
        "spotId": 1,
        "review": "This was an awesome spot!",
        "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": "Validation error",
        "statusCode": 400,
        "errors": {
          "review": "Review text is required",
          "stars": "Stars must be an integer from 1 to 5"
        }
      }
  • Error response: Couldn't find a Spot with the specified id

    • Status Code: 404

    • Headers:

      • Content-Type: application/json
    • Body:

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

    • Status Code: 403

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "message": "User already has a review for this spot",
        "statusCode": 403
      }

Add an Image to a Review based on the Review's id

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

  • Require Authentication: true

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

  • Request

    • Method: POST

    • URL: /api/reviews/:reviewId/images

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "url": "image url"
      }
  • Successful Response

    • Status Code: 200

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "id": 1,
        "url": "image url"
      }
  • 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",
        "statusCode": 404
      }
  • Error response: Cannot add any more images because there is a maximum of 10 images per resource

    • Status Code: 403

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "message": "Maximum number of images for this resource was reached",
        "statusCode": 403
      }

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: /api/reviews/:reviewId

    • Headers:

      • Content-Type: application/json
    • Body:

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

    • Status Code: 200

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "id": 1,
        "userId": 1,
        "spotId": 1,
        "review": "This was an awesome spot!",
        "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": "Validation error",
        "statusCode": 400,
        "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",
        "statusCode": 404
      }

Delete a Review

Delete an existing review.

  • Require Authentication: true

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

  • Request

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

    • Status Code: 200

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "message": "Successfully deleted",
        "statusCode": 200
      }
  • 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",
        "statusCode": 404
      }

BOOKINGS

Get all of the Current User's Bookings

Return all the bookings that the current user has made.

  • Require Authentication: true

  • Request

    • Method: GET
    • URL: /api/bookings/current
    • Body: none
  • Successful Response

    • Status Code: 200

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "Bookings": [
          {
            "id": 1,
            "spotId": 1,
            "Spot": {
              "id": 1,
              "ownerId": 1,
              "address": "123 Disney Lane",
              "city": "San Francisco",
              "state": "California",
              "country": "United States of America",
              "lat": 37.7645358,
              "lng": -122.4730327,
              "name": "App Academy",
              "price": 123,
              "previewImage": "image url"
            },
            "userId": 2,
            "startDate": "2021-11-19",
            "endDate": "2021-11-20",
            "createdAt": "2021-11-19 20:39:36",
            "updatedAt": "2021-11-19 20:39:36"
          }
        ]
      }

Get all Bookings for a Spot based on the Spot's id

Return all the bookings for a spot specified by id.

  • Require Authentication: true

  • Request

    • Method: GET
    • URL: /api/spots/:spotId/bookings
    • Body: none
  • Successful Response: If you ARE NOT the owner of the spot.

    • Status Code: 200

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "Bookings": [
          {
            "spotId": 1,
            "startDate": "2021-11-19",
            "endDate": "2021-11-20"
          }
        ]
      }
  • Successful Response: If you ARE the owner of the spot.

    • Status Code: 200

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "Bookings": [
          {
            "User": {
              "id": 2,
              "firstName": "John",
              "lastName": "Smith"
            },
            "id": 1,
            "spotId": 1,
            "userId": 2,
            "startDate": "2021-11-19",
            "endDate": "2021-11-20",
            "createdAt": "2021-11-19 20:39:36",
            "updatedAt": "2021-11-19 20:39:36"
          }
        ]
      }
  • Error response: Couldn't find a Spot with the specified id

    • Status Code: 404

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "message": "Spot couldn't be found",
        "statusCode": 404
      }

Create a Booking from a Spot based on the Spot's id

Create and return a new booking from a spot specified by id.

  • Require Authentication: true

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

  • Request

    • Method: POST

    • URL: /api/spots/:spotId/bookings

    • Body:

      {
        "startDate": "2021-11-19",
        "endDate": "2021-11-20"
      }
  • Successful Response

    • Status Code: 200

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "id": 1,
        "spotId": 1,
        "userId": 2,
        "startDate": "2021-11-19",
        "endDate": "2021-11-20",
        "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": "Validation error",
        "statusCode": 400,
        "errors": {
          "endDate": "endDate cannot be on or before startDate"
        }
      }
  • Error response: Couldn't find a Spot with the specified id

    • Status Code: 404

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "message": "Spot couldn't be found",
        "statusCode": 404
      }
  • Error response: Booking conflict

    • Status Code: 403

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "message": "Sorry, this spot is already booked for the specified dates",
        "statusCode": 403,
        "errors": {
          "startDate": "Start date conflicts with an existing booking",
          "endDate": "End date conflicts with an existing booking"
        }
      }

Edit a Booking

Update and return an existing booking.

  • Require Authentication: true

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

  • Request

    • Method: PUT

    • URL: /api/bookings/:bookingId

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "startDate": "2021-11-19",
        "endDate": "2021-11-20"
      }
  • Successful Response

    • Status Code: 200

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "id": 1,
        "spotId": 1,
        "userId": 2,
        "startDate": "2021-11-19",
        "endDate": "2021-11-20",
        "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": "Validation error",
        "statusCode": 400,
        "errors": {
          "endDate": "endDate cannot come before startDate"
        }
      }
  • Error response: Couldn't find a Booking with the specified id

    • Status Code: 404

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "message": "Booking couldn't be found",
        "statusCode": 404
      }
  • Error response: Can't edit a booking that's past the end date

    • Status Code: 403

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "message": "Past bookings can't be modified",
        "statusCode": 403
      }
  • Error response: Booking conflict

    • Status Code: 403

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "message": "Sorry, this spot is already booked for the specified dates",
        "statusCode": 403,
        "errors": {
          "startDate": "Start date conflicts with an existing booking",
          "endDate": "End date conflicts with an existing booking"
        }
      }

Delete a Booking

Delete an existing booking.

  • Require Authentication: true

  • Require proper authorization: Booking must belong to the current user or the Spot must belong to the current user

  • Request

    • Method: DELETE
    • URL: /api/bookings/:bookingId
    • Body: none
  • Successful Response

    • Status Code: 200

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "message": "Successfully deleted",
        "statusCode": 200
      }
  • Error response: Couldn't find a Booking with the specified id

    • Status Code: 404

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "message": "Booking couldn't be found",
        "statusCode": 404
      }
  • Error response: Bookings that have been started can't be deleted

    • Status Code: 403

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "message": "Bookings that have been started can't be deleted",
        "statusCode": 403
      }

IMAGES

Delete a Spot Image

Delete an existing image for a Spot.

  • Require Authentication: true

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

  • Request

    • Method: DELETE
    • URL: /api/spot-images/:imageId
    • Body: none
  • Successful Response

    • Status Code: 200

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "message": "Successfully deleted",
        "statusCode": 200
      }
  • Error response: Couldn't find a Spot Image with the specified id

    • Status Code: 404

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "message": "Spot Image couldn't be found",
        "statusCode": 404
      }

Delete a Review Image

Delete an existing image for a Review.

  • Require Authentication: true

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

  • Request

    • Method: DELETE
    • URL: /api/review-images/:imageId
    • Body: none
  • Successful Response

    • Status Code: 200

    • Headers:

      • Content-Type: application/json
    • Body:

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

    • Status Code: 404

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "message": "Review Image couldn't be found",
        "statusCode": 404
      }

Add Query Filters to Get All Spots

Return spots filtered by query parameters.

  • Require Authentication: false

  • Request

    • Method: GET
    • URL: /api/spots
    • Query Parameters
      • page: integer, minimum: 1, maximum: 10, default: 1
      • size: integer, minimum: 1, maximum: 20, default: 20
      • minLat: decimal, optional
      • maxLat: decimal, optional
      • minLng: decimal, optional
      • maxLng: decimal, optional
      • minPrice: decimal, optional, minimum: 0
      • maxPrice: decimal, optional, minimum: 0
    • Body: none
  • Successful Response

    • Status Code: 200

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "Spots": [
          {
            "id": 1,
            "ownerId": 1,
            "address": "123 Disney Lane",
            "city": "San Francisco",
            "state": "California",
            "country": "United States of America",
            "lat": 37.7645358,
            "lng": -122.4730327,
            "name": "App Academy",
            "description": "Place where web developers are created",
            "price": 123,
            "createdAt": "2021-11-19 20:39:36",
            "updatedAt": "2021-11-19 20:39:36",
            "avgRating": 4.5,
            "previewImage": "image url"
          }
        ],
        "page": 2,
        "size": 25
      }
  • Error Response: Query parameter validation errors

    • Status Code: 400

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "message": "Validation Error",
        "statusCode": 400,
        "errors": {
          "page": "Page must be greater than or equal to 1",
          "size": "Size must be greater than or equal to 1",
          "maxLat": "Maximum latitude is invalid",
          "minLat": "Minimum latitude is invalid",
          "minLng": "Minimum longitude is invalid",
          "maxLng": "Maximum longitude is invalid",
          "minPrice": "Minimum price must be greater than or equal to 0",
          "maxPrice": "Maximum price must be greater than or equal to 0"
        }
      }

airbnb's People

Contributors

dcraderdev avatar

Stargazers

Matthew David avatar

Watchers

 avatar

airbnb's Issues

Get all Bookings for a Spot based on the Spot's id

Return all the bookings for a spot specified by id.

  • An authenticated user is required for a successful response
  • Seed data exists in the database for bookings to be returned.
  • Successful response includes only bookings for the specified spot
  • If you are NOT the owner of the spot, booking data returned includes the
    spotId, startDate, and endDate for each booking
  • If you ARE the owner of the spot, booking data returned includes the id
    spotId, userId, startDate, endDate, createdAt, and updatedAt for
    each booking
  • If you ARE the owner of the spot, booking data returns associated data for
    User, including the id, firstName, and lastName
  • Error response with status 404 is given when a spot does not exist with
    the provided id

Delete a Review

  • An authenticated user is required for a successful response
  • Only the owner of the review is authorized to delete
  • Review record is removed from the database after request
  • Success response includes a message indicating a successful deletion
  • Error response with status 404 is given when a spot does not exist with
    the provided id

Log In a User (Feature 0)

  • Successful response includes the user's id, firstName, lastName,
    email, and token
  • Error response with status 401 is given when invalid credentials are given
  • Error response with status 400 is given when body validations for the
    email, firstName, or lastName are violated

Add Query Filters to Get All Spots

Return spots filtered by query parameters.

  • Query parameters are accepted for page, size, minLat, maxLat,
    minLng, maxLng, minPrice, and maxPrice
  • Default values are provided for the page and size parameters
  • Successful response includes only spots in the database that meet the
    specified query parameters criteria.
  • Spot data returned includes the id, ownerId, address, city,
    state, country, lat, lng, name, description, price, createdAt,
    updatedAt, and previewImage for each spot
  • Successful response includes the page and size of the returned payload
  • Error response with status 400 is given when query parameter validations
    for the page, size, minLat, maxLat, minLng, maxLng, minPrice, or
    maxPrice are violated

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

  • An authenticated user is required for a successful response
  • New review exists in the database after request
  • Review data returned includes the id, userId, spotId, review,
    stars, createdAt, and updatedAt
  • Error response with status 400 is given when body validations for the
    review or stars are violated
  • Error response with status 404 is given when a spot does not exist with
    the provided id
  • Error response with status 403 is given when a review already exists for
    the spot from the current user

Edit a Review

  • An authenticated user is required for a successful response
  • Only the owner of the review is authorized to edit
  • Review record is updated in the database after request
  • Review data returned includes the id, userId, spotId, review,
    stars, createdAt, and updatedAt
  • Error response with status 400 is given when body validations for the
    review, or stars are violated
  • Error response with status 404 is given when a review does not exist with
    the provided id

Get all Spots

  • Seed data exists in the database for spots to be returned.
  • Successful response includes each spot in the database.
  • Spot data returned includes the id, ownerId, address, city,
    state, country, lat, lng, name, description, price, createdAt,
    updatedAt, previewImage, and avgRating

Edit a Booking

Update and return an existing booking.

  • An authenticated user is required for a successful response
  • Only the owner of the booking is authorized to edit
  • Booking record is updated in the database after request
  • Booking data returned includes the id, userId, spotId, startDate,
    endDate, createdAt, and updatedAt
  • Error response with status 404 is given when a booking does not exist with
    the provided id
  • Error response with status 400 is given when it is past the booking's
    endDate (no editing of past bookings)
  • Error response with status 403 is given when a booking already exists for
    the spot on the specified dates

Sign Up a User (Feature 0)

  • New user exists in the database after request
  • Successful response includes newly created id, firstName, lastName,
    email, and token
  • Error response with status 403 is given when the specified email already
    exists
  • Error response with status 400 is given when body validations for the
    email, firstName, or lastName are violated

Get all Spots owned by the Current User

  • An authenticated user is required for a successful response
  • Successful response includes only spots created by the current user
  • Spot data returned includes the id, ownerId, address, city,
    state, country, lat, lng, name, description, price, createdAt,
    updatedAt, previewImage, and avgRating

Delete an Image for a Spot

  • An authenticated user is required for a successful response
  • Only the owner of the spot is authorized to delete
  • Image record is removed from the database after request
  • Success response includes a message indicating a successful deletion
  • Error response with status 404 is given when a spot image does not exist
    with the provided id

Delete a Booking

Delete an existing booking.

  • An authenticated user is required for a successful response
  • Only the owner of the booking or the owner of the spot is authorized to
    delete the booking
  • Booking record is removed from the database after request
  • Success response includes a message indicating a successful deletion
  • Error response with status 404 is given when a spot does not exist with
    the provided id
  • Error response with status 400 is given when it is past the booking's
    startDate (no deleting of current or past bookings)

Get all of the Current User's Bookings

Return all the bookings that the current user has made.

  • An authenticated user is required for a successful response
  • Successful response includes only bookings created by the current user
  • Booking data returned includes the id, spotId, userId, startDate,
    endDate, createdAt, and updatedAt
  • Booking data returns associated data for Spot, including the id,
    ownerId, address, city, state, country, lat, lng, name,
    price and previewImage

Add an Image to a Spot based on the Spot's id

  • An authenticated user is required for a successful response
  • Only the owner of the spot is authorized to add an image
  • New image exists in the database after request
  • Image data returned includes the id, url, and preview
  • Error response with status 404 is given when a spot does not exist with
    the provided id

Create a Spot

  • An authenticated user is required for a successful response
  • New spot exists in the database after request
  • Spot data returned includes the id, ownerId, address, city,
    state, country, lat, lng, name, description, price, createdAt,
    and updatedAt
  • Error response with status 400 is given when body validations for the
    address, city, state, country, lat, lng, name, description, or price are violated

Authentication Required

All endpoints that require a current user to be logged in receive a standard
authentication response.

  • Authentication middleware responds with error status 401 when
    authentication is not provided

Delete an Image for a Review

Delete an existing image for a Review.

  • An authenticated user is required for a successful response
  • Only the owner of the review is authorized to delete
  • Image record is removed from the database after request
  • Success response includes a message indicating a successful deletion
  • Error response with status 404 is given when a review image does not exist
    with the provided id

Delete a Spot

  • An authenticated user is required for a successful response
  • Only the owner of the spot is authorized to delete
  • Spot record is removed from the database after request
  • Success response includes a message indicating a successful deletion
  • Error response with status 404 is given when a spot does not exist with
    the provided id

Get all Reviews of the Current User

  • An authenticated user is required for a successful response
  • Successful response includes only reviews created by the current user
  • Review data returned includes the id, userId, spotId, review,
    stars, createdAt, and updatedAt
  • Review data returns associated data for User, including the id,
    firstName, and lastName
  • Review data returns associated data for Spot, including the id,
    ownerId, address, city, state, country, lat, lng, name,
    price, and previewImage
  • Review data returns associated data for ReviewImages, an array of image
    data including the id and url

Get the Current User (Feature 0)

  • An authenticated user is required for a successful response
  • Successful response includes the user's id, firstName, lastName,
    email, and token

Add an Image to a Review based on the Review's id

  • An authenticated user is required for a successful response
  • Only the owner of the review is authorized to add an image
  • New image exists in the database after request
  • Image data returned includes the id and url
  • Error response with status 404 is given when a review does not exist with
    the provided id
  • Error response with status 400 is given when the maximum number of images
    have been added for the review

Get details for a Spot from an id

  • Successful response includes data only for the specified spot
  • Spot data returned includes the id, ownerId, address, city,
    state, country, lat, lng, name, description, price, createdAt,
    and updatedAt
  • Spot data returns aggregate data for numReviews and avgStarRating
  • Spot data returns associated data for SpotImages, an array of image
    data including the id, url, and preview
  • Spot data returns associated data for Owner, including the id,
    firstName, and lastName
  • Error response with status 404 is given when a spot does not exist with
    the provided id

Create a Booking from a Spot based on the Spot's id

Create and return a new booking from a spot specified by id.

  • - [ ] An authenticated user is required for a successful response
  • A user is only authorized to create a booking if they do NOT own the spot
  • New booking exists in the database after request
  • Booking data returned includes the id, userId, spotId, startDate,
    endDate, createdAt, and updatedAt
  • Error response with status 404 is given when a spot does not exist with
    the provided id
  • Error response with status 403 is given when a booking already exists for
    the spot on the specified dates

Get all Reviews by a Spot's id

  • Seed data exists in the database for reviews to be returned.
  • Successful response includes only reviews for the specified spot
  • Review data returned includes the id, userId, spotId, review,
    stars, createdAt, and updatedAt
  • Review data returns associated data for User, including the id,
    firstName, and lastName
  • Review data returns associated data for ReviewImages, an array of image
    data including the id and url
  • Error response with status 404 is given when a spot does not exist with
    the provided id

Edit a Spot

  • An authenticated user is required for a successful response
  • Only the owner of the spot is authorized to edit
  • Spot record is updated in the database after request
  • Spot data returned includes the id, ownerId, address, city,
    state, country, lat, lng, name, description, price, createdAt,
    and updatedAt
  • Error response with status 400 is given when body validations for the
    address, city, state, country, lat, lng, name, description, or price are violated
  • Error response with status 404 is given when a spot does not exist with
    the provided id

Authorization Required

  • Authorization middleware responds with error status 403 when
    an authenticated user does not have the correct role(s) or permission(s)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.