heather-yaple / auth-me-project

Repo for Auth Me project
0 stars 1 forks source link

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

Closed heather-yaple closed 1 month ago

heather-yaple commented 2 months ago

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

joe-corcoran commented 1 month ago

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

Route path: /api/spots/:spotId/bookings

Headers:

Content-Type: application/json Body:

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

Status Code: 201

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": "Bad Request", // (or "Validation error" if generated by Sequelize), "errors": { "startDate": "startDate cannot be in the past", "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" } Error response: Booking conflict

Status Code: 403

Headers:

Content-Type: application/json Body:

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