Heroku App URL (need before each method url): https://rvbnb.herokuapp.com
- Register User: .post() /api/auth/register
- Login User: .post() /api/auth/login
- Get Listings: .get() /api/listings
- Get Listing by Id: get() /api/listings/:id
- Post Listings: .post() /api/listings
- Delete Listing: .delete() /api/listings/:id
- Update Listing: .put() /api/listings/:id
- Get All Reservations: .get() /api/listings/all/reservations
- Get Reservation by Listing Id: .get() /api/listings/:id/reservations
- Post Reservation: .post() /api/listings/:id/reservations
- Delete Reservation: .delete() /api/listings/reservations/:id
- Update Reservation: .put() api/listings/:listing_id/reservations/:id
Register a user
method url: /api/auth/register
http method: [POST]
Body
| name | type | required | description |
|---|---|---|---|
| username | String | Yes | Must be unique/ Must be < 24 char |
| password | String | Yes | Must be < 24 char |
| is_land_owner | Boolean | Yes | role of the user |
**Example
{
username: 'andrew',
password: 'allen',
is_land_owner: true
}
Response 201 (created)
{
message: `User created`
}
Login a user
method url: /api/auth/login
http method: [POST]
Body
| name | type | required |
|---|---|---|
| username | String | Yes |
| password | String | Yes |
Example
{
username: 'andrew',
password: 'allen'
}
Response 200 (ok)
{
token: 'a super duper long jwt token',
id: 1,
username: 'andrew',
is_land_owner: 1(T) / 0(F)
}
401 (Unauthorized) Example response
{
"message": "Invalid Credentials"
}
404 (not found) Example response
{
"message": "User not found"
}
Gets listings
method url: /api/listings
http method: [GET]
Response 200 (ok)
[
{
"id": 1,
"owner_id": 1,
"location": "my street 7",
"description": "some desc",
"price_per_day": 19.99,
"photo": "a photo url"
},
{
"id": 2,
"owner_id": 1,
"location": "my street 3",
"description": "some desc update v2",
"price_per_day": 19.99,
"photo": "a photo url"
},
{
"id": 3,
"owner_id": 1,
"location": "my street 4",
"description": "some desc",
"price_per_day": 19.99,
"photo": "a photo url"
}
]
Gets a specific listing and returns reservations of specific listing
If a RV Owner requests this endpoint they are only given reservations tied to them
A Land Owner will get all reservations tied to the listing
method url: /api/listings/:id
http method: [GET]
Response 200 (ok)
{
"listing": {
"id": 6,
"owner_id": 1,
"location": "my street 1",
"description": "some desc",
"price_per_day": 20,
"photo": "a photo url"
},
"reservations": [
{
"id": 2,
"listing_id": 1,
"user_id": 1,
"reserve_date_start": "2019-01-10T00:00:00.000Z",
"reserve_date_end": "2019-01-16T00:00:00.000Z"
},
{
"id": 3,
"listing_id": 1,
"user_id": 2,
"reserve_date_start": "2019-01-17T00:00:00.000Z",
"reserve_date_end": "2019-01-20T00:00:00.000Z"
},
{
"id": 4,
"listing_id": 1,
"user_id": 2,
"reserve_date_start": "2019-01-21T00:00:00.000Z",
"reserve_date_end": "2019-01-26T00:00:00.000Z"
}
]
}
404 (not found) Example response
{
message: `Listing does not exist`
}
method url: /api/listings
http method: [POST]
Body
| name | type | required |
|---|---|---|
| location | string | Yes (Unique) |
| description | String | Yes |
| price_per_day | decimal | Yes |
| photo | String | Yes (Doesn't actually do anything) |
Example
{
"location": "my street 5",
"description": "some desc",
"price_per_day": 19.99,
"photo": "a photo url"
}
Response 201 (created)
{
message: 'Listing created'
}
401 (Unauthorized) Example response
{
message: 'Logged in user has no access'
}
400 (location is no unique) Example response
{
message: 'Location Already Exists'
}
Deletes a listing and all reservations tied to the listing
method url: /api/listings/:id
http method: [DELETE]
Response 200 (ok)
{
message: 'Listing deleted'
}
404 (not found) Example response
{
message: `Listing does not exist`
}
401 (Unauthorized) Example response
{
message: 'Logged in user has no access'
}
Does not need entire object, only the key: value that is being updated
method url: /api/listings/:id
http method: [PUT]
Body
| name | type |
|---|---|
| location | string |
| description | String |
| price_per_day | decimal |
| photo | String |
Example
{
"price_per_day": 19.99
}
Response 200 (ok)
{
message: 'Listing updated'
}
404 (not found) Example response
{
message: `Listing does not exist`
}
401 (Unauthorized) Example response
{
message: 'Logged in user has no access'
}
Gets all reservations
Only Rv Owners can request this end point, they get all the reservations tied to their id
See '/api/listings/:id/reservations' for Land Owners
method url: /api/listings/all/reservations
http method: [GET]
Response 200 (ok)
[
{
"id": 36,
"listing_id": 6,
"user_id": 2,
"reserve_date_start": "01/01/2019",
"reserve_date_end": "01/03/2019"
},
{
"id": 37,
"listing_id": 5,
"user_id": 2,
"reserve_date_start": "01/20/2019",
"reserve_date_end": "01/26/2019"
}
]
401 (Unauthorized) Example response
{
message: 'Land Owners cannot have reservations'
}
Gets all reservations of a specific listing
Land Owners get all reservations on the listing
Rv Owners get the reservation(s) tied to their id
method url: /api/listings/:id/reservations
http method: [GET]
Response 200 (ok)
[
{
"id": 33,
"listing_id": 6,
"user_id": 1,
"reserve_date_start": "01/15/2019",
"reserve_date_end": "01/20/2019"
},
{
"id": 35,
"listing_id": 6,
"user_id": 1,
"reserve_date_start": "01/13/2019",
"reserve_date_end": "01/22/2019"
},
{
"id": 36,
"listing_id": 6,
"user_id": 2,
"reserve_date_start": "01/01/2019",
"reserve_date_end": "01/03/2019"
}
]
404 (Not Found) Example response
{
message: `Listing does not exist`
}
Posting a reservation to a listing
Land Owners cannot POST reservations
method url: /api/listings/:id/reservations
http method: [POST]
Body
| name | type | required |
|---|---|---|
| reserve_date_start | string | Yes (mm/dd/yyyy) |
| reserve_date_end | String | Yes (mm/dd/yyyy) |
Example
{
"reserve_date_start": "01/15/2019",
"reserve_date_end": "01/17/2019"
}
Response 201 (created)
{
"message": "Reservation created"
}
401 (Unauthorized) Example response
{
message: 'Land owners cannot make reservations'
}
400 (date conflicts) Example response
{
message: 'Conflicting reservations'
}
Deletes a specific reservation
method url: /api/listings/reservations/:id
http method: [DELETE]
Response 200 (ok)
{
message: 'Listing deleted'
}
404 (not found) Example response
{
message: `Reservation does not exist`
}
method url: api/listings/:listing_id/reservations/:id
http method: [PUT]
Body
| name | type | required |
|---|---|---|
| reserve_date_start | string | Yes (mm/dd/yyyy) |
| reserve_date_end | String | Yes (mm/dd/yyyy) |
Example
{
"reserve_date_start": "01/02/2019",
"reserve_date_end": "01/05/2019"
}
Response 200 (ok)
{
message: 'Reservation updated'
}
404 (not found) Example response
{
message: `Reservation does not exist`
}
400 Example response
{
message: 'Conflicting reservations'
}