API Documentation - Risclover/airbnbeezy GitHub Wiki

⇦ Return Home

Table of Contents

currentUser

(Back to Top ^)

Get the current user: GET /api/session

Response:

Status: 200,
Content-Type: "application/json",
Body:
{
  "id": 1,
  "firstName": "John",
  "lastName": "Smith",
  "email": "[email protected]",
  "username": "JohnSmith"
}
Log in a user: POST /api/session

Request:

Content-Type: "application/json",
Body:
{
    "credential": "[email protected]"
    "password": "secret password"
}

Response:

Status Code: 200,
Content-Type: "application/json",
Body:
{
  "id": 1,
  "firstName": "John",
  "lastName": "Smith",
  "email": "[email protected]",
  "username": "JohnSmith",
  "token": ""
}

Error: Invalid Credentials

Status Code: 401,
Content-Type: "application/json",
Body:
{
  "message": "Invalid credentials",
  "statusCode": 401
}

Error: Body validation errors

Status Code: 400,
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: POST /api/users

Request:

Content-Type: "application/json",
Body:
{
  "firstName": "John",
  "lastName": "Smith",
  "email": "[email protected]",
  "username": "JohnSmith",
  "password": "secret password"
}

Response:

Status Code: 200,
Content-Type: "application/json",
Body:
{
  "id": 1,
  "firstName": "John",
  "lastName": "Smith",
  "email": "[email protected]",
  "username": "JohnSmith",
  "token": ""
}

Error: User already exists with the specified email

Status Code: 403,
Content-Type: "application/json",
Body:
{
  "message": "User already exists",
  "statusCode": 403,
  "errors": {
    "email": "User with that email already exists"
  }
}

Error: User already exists with the specified username

Status Code: 403,
Content-Type: "application/json",
Body:
{
  "message": "User already exists",
  "statusCode": 403,
  "errors": {
    "username": "User with that username already exists"
  }
}

Error: Body validation errors

Status Code: 400,
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

(Back to Top ^)

Get all spots: GET /api/spots

Response

Status Code: 200,
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: GET /api/spots/current

Response

Status Code: 200,
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: GET /api/spots/:spotId

Response

Status Code: 200,
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: Couldn't find a Spot with the specified id

Status Code: 404,
Content-Type: "application/json",
Body:
{
  "message": "Spot couldn't be found",
  "statusCode": 404
}
Create a spot: POST /api/spots

Request

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
}

Response

Status Code: 201,
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: Body validation error

Status Code: 400,
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: POST /api/spots/:spotId/images

Request

Content-Type: "application/json",
Body:
{
  "url": "image url",
  "preview": true
}

Response

Status Code: 200,
Content-Type: "application/json",
Body:
{
  "id": 1,
  "url": "image url",
  "preview": true
}

Error: Couldn't find a Spot with the specified id

Status Code: 404,
Content-Type: "application/json",
Body:
{
  "message": "Spot couldn't be found",
  "statusCode": 404
}
Edit a Spot: PUT /api/spots/:spotId

Request

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
}

Response

Status Code: 200,
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: Body validation error

Status Code: 400,
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: Couldn't find a Spot with the specified id

Status Code: 404,
Content-Type: "application/json",
Body:
{
  "message": "Spot couldn't be found",
  "statusCode": 404
}
Delete a Spot: DELETE /api/spots/:spotId

Response

Status Code: 200,
Content-Type: "application/json",
Body:
{
  "message": "Successfully deleted",
  "statusCode": 200
}

Error: Couldn't find a Spot with the specified id

Status Code: 404,
Content-Type: "application/json",
Body:
{
  "message": "Spot couldn't be found",
  "statusCode": 404
}

Reviews

(Back to Top ^)

Get all Reviews of the Current User: GET /api/reviews/current

Response

Status Code: 200,
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: GET /api/spots/:spotId/reviews

Response

Status Code: 200,
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: Couldn't find a Spot with the specified id

Status Code: 404,
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: POST /api/spots/:spotId/reviews

Request

Content-Type: "application/json",
Body:
{
  "review": "This was an awesome spot!",
  "stars": 5,
}

Response

Status Code: 201,
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: Body validation errors

Status Code: 400,
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: Couldn't find a Spot with the specified id

Status Code: 404,
Content-Type: "application/json",
Body:
{
  "message": "Spot couldn't be found",
  "statusCode": 404
}

Error: Review from the current user already exists for the Spot

Status Code: 403,
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: POST /api/reviews/:reviewId/images

Request

Content-Type: "application/json",
Body:
{
    "url": "image url"
}

Response

Status Code: 200,
Content-Type: "application/json",
Body:
{
  "id": 1,
  "url": "image url"
}

Error: Couldn't find a Review with the specified id

Status Code: 404,
Content-Type: "application/json",
Body:
{
  "message": "Review couldn't be found",
  "statusCode": 404
}

Error: Cannot add any more images because there is a maximum of 10 images per resource

Status Code: 403
Content-Type: "application/json",
Body:
{
  "message": "Maximum number of images for this resource was reached",
  "statusCode": 403
}
Edit a Review: PUT /api/reviews/:reviewId

Request

Content-Type: "application/json",
Body:
{
  "review": "This was an awesome spot!",
  "stars": 5,
}

Response

Status Code: 200,
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: Body validation errors

Status Code: 400,
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: Couldn't find a Review with the specified id

Status Code: 404,
Content-Type: "application/json",
Body:
{
  "message": "Review couldn't be found",
  "statusCode": 404
}
Delete a Review: DELETE /api/reviews/:reviewId

Response

Status Code: 200,
Content-Type: "application/json",
Body:
{
  "message": "Successfully deleted",
  "statusCode": 200
}

Error: Couldn't find a Review with the specified id

Status Code: 404,
Content-Type: "application/json",
Body:
{
  "message": "Review couldn't be found",
  "statusCode": 404
}

Bookings

(Back to Top ^)

Get all of the Current User's Bookings: GET /api/bookings/current

Response

Status Code: 200,
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: GET /api/spots/:spotId/bookings

Response - If you ARE NOT the owner of the spot

Status Code: 200,
Content-Type: "application/json",
Body:
{
  "Bookings": [
    {
      "spotId": 1,
      "startDate": "2021-11-19",
      "endDate": "2021-11-20"
    }
  ]
}

Response - If you ARE the owner of the spot

Status Code: 200,
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: Couldn't find a Spot with the specified id

Status Code: 404,
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: POST /api/spots/:spotId/bookings

Request

Body:
{
  "startDate": "2021-11-19",
  "endDate": "2021-11-20"
}

Response

Status Code: 200,
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: Body validation errors

Status Code: 400,
Content-Type: "application/json",
Body:
{
  "message": "Validation error",
  "statusCode": 400,
  "errors": {
    "endDate": "endDate cannot be on or before startDate"
  }
}

Error: Couldn't find a Spot with the specified id

Status Code: 404,
Content-Type: "application/json",
Body:
{
  "message": "Spot couldn't be found",
  "statusCode": 404
}

Error: Booking conflict

Status Code: 403
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: PUT /api/bookings/:bookingId

Request

Content-Type: "application/json",
Body:
{
  "startDate": "2021-11-19",
  "endDate": "2021-11-20"
}

Response

Status Code: 200,
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: Body validation errors

Status Code: 400,
Content-Type: "application/json",
Body:
{
  "message": "Validation error",
  "statusCode": 400,
  "errors": {
    "endDate": "endDate cannot come before startDate"
  }
}

Error: Couldn't find a Booking with the specified id

Status Code: 404,
Content-Type: "application/json",
Body:
{
  "message": "Booking couldn't be found",
  "statusCode": 404
}

Error: Can't edit a booking that's past the due date

Status Code: 403,
Content-Type: "application/json",
Body:
{
  "message": "Past bookings can't be modified",
  "statusCode": 403
}

Error: Booking conflict

Status Code: 403,
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 /api/bookings/:bookingId

Response

Status Code: 200,
Content-Type: "application/json",
Body:
{
  "message": "Successfully deleted",
  "statusCode": 200
}

Error: Couldn't find a Booking with the specified id

Status Code: 404,
Content-Type: "application/json",
Body:
{
  "message": "Booking couldn't be found",
  "statusCode": 404
}

Error: Bookings that have been started can't be deleted

Status Code: 403,
Content-Type: "application/json",
Body:
{
  "message": "Bookings that have been started can't be deleted",
  "statusCode": 403
}

Images

(Back to Top ^)

Delete a Spot Image: DELETE /api/spot-images/:imageId

Response

Status Code: 200,
Content-Type: "application/json",
Body:
{
  "message": "Successfully deleted",
  "statusCode": 200
}

Error: Couldn't find a Spot Image with the specified id

Status Code: 404,
Content-Type: "application/json",
Body:
{
  "message": "Spot Image couldn't be found",
  "statusCode": 404
}
Delete a Review Image: DELETE /api/review-images/:imageId

Response

Status Code: 200,
Content-Type: "application/json",
Body:
{
  "message": "Successfully deleted",
  "statusCode": 200
}

Error: Couldn't find a Review Image with the specified id

Status Code: 404,
Content-Type: "application/json",
Body:
{
  "message": "Review Image couldn't be found",
  "statusCode": 404
}
⚠️ **GitHub.com Fallback** ⚠️