-
Notifications
You must be signed in to change notification settings - Fork 3
API Routes
#Users: 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/users/int:id Body: none Successful Response Status Code: 200 Headers: Content-Type: application/json Body: { "user": { "id": 1, "firstName": "John", "lastName": "Smith", "email": "john.smith@gmail.com", "owner": "False" "phoneNumber”: "111-111-1111" } } 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/auth/login Headers: Content-Type: application/json Body: { "email": "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", "owner": "False" "phoneNumber”: "111-111-1111" } } 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/auth/signup
Headers:
Content-Type: application/json
Body:
{
"id": 1,
"firstName": "John",
"lastName": "Smith",
"email": "john.smith@gmail.com",
"owner": "False"
"phoneNumber”: "111-111-1111"
"password": "secret password"
}
Successful Response
Status Code: 200
Headers:
Content-Type: application/json
Body:
{
"id": 1,
"firstName": "John",
"lastName": "Smith",
"email": "john.smith@gmail.com",
"owner": "False"
"phoneNumber”: "111-111-1111"
}
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: Body validation errors
Status Code: 400
Headers:
Content-Type: application/json
Body:
{
"message": "Validation error",
"statusCode": 400,
"errors": {
"email": "Invalid email",
"phoneNumber": "Phone is required",
"firstName": "First Name is required",
"lastName": "Last Name is required"
}
}
Returns all the restaurants.
-
Require Authentication: false
-
Request
- Method: GET
- URL: /api/restaurants
- Body: none
-
Successful Response
-
Status Code: 200
-
Headers:
- Content-Type: application/json
-
Body:
{ "Restaurants": [ { "id": 1, "ownerId": 1, "restaurauntName": "Apple Academy", "coverImage": "www.photo.example", "address": "123 Disney Lane", "city": "San Francisco", "state": "California", "zipcode": 10021, "country": "United States of America", "cuisineType": “Yummy”, “priceRange”: 3, “phoneNumber”: 123456789, “openHours”: “10 am”, “closingHours” : “3pm”, "createdAt": "2021-11-19 20:39:36", "updatedAt": "2021-11-19 20:39:36", "avgRating": 4.5, } ] }
-
Returns all the restaurants owned (created) by the current user.
-
Require Authentication: true
-
Request
-
Method: GET
-
URL: /api/user/restaurants/
-
Body: none
-
-
Successful Response
-
Status Code: 200
-
Headers:
- Content-Type: application/json
-
Body:
{ "Restaurants": [ { "id": 1, "ownerId": 1, "restaurauntName": "Apple Academy", "coverImage": "www.photo.example", "address": "123 Disney Lane", "city": "San Francisco", "state": "California", "zipcode": 10021, "country": "United States of America", "cuisineType": “Yummy”, “priceRange”: 3, “phoneNumber”: 123456789, “openHours”: “10 am”, “closingHours” : “3pm”, "createdAt": "2021-11-19 20:39:36", "updatedAt": "2021-11-19 20:39:36", "avgRating": 4.5, } ] }
-
Returns the details of a restaurant specified by its id.
-
Require Authentication: false
-
Request
- Method: GET
- URL: /api/restaurants/:restaurantId
- Body: none
-
Successful Response
-
Status Code: 200
-
Headers:
- Content-Type: application/json
-
Body:
{ "id": 1, "ownerId": 1, "restaurauntName": "Apple Academy", "coverImage": "www.photo.example", "address": "123 Disney Lane", "city": "San Francisco", "state": "California", "zipcode": 10021, "country": "United States of America", "cuisineType": “Yummy”, “priceRange”: 3, “phoneNumber”: 123456789, “openHours”: “10 am”, “closingHours” : “3pm”, "createdAt": "2021-11-19 20:39:36", "updatedAt": "2021-11-19 20:39:36", "numReviews": 5, "avgRating": 4.5, "ReviewImages": [ { "id": 1, "url": "image url", }, { "id": 2, "url": "image url", } ], "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", "statusCode": 404 }
-
Creates and returns a new restaurant.
-
Require Authentication: true
-
Request
-
Method: POST
-
URL: /api/restaurants
-
Headers:
- Content-Type: application/json
-
Body:
{ "ownerId": 1, "restaurauntName": "Apple Academy", "coverImage": "www.photo.example", "address": "123 Disney Lane", "city": "San Francisco", "state": "California", "zipcode": 10021, "country": "United States of America", "cuisineType": “Yummy”, “priceRange”: 3, “phoneNumber”: 123456789, “openHours”: “10 am”, “closingHours” : “3pm”, }
-
-
Successful Response
-
Status Code: 201
-
Headers:
- Content-Type: application/json
-
Body:
{ "id": 1, "ownerId": 1, "restaurauntName": "Apple Academy", "coverImage": "www.photo.example", "address": "123 Disney Lane", "city": "San Francisco", "state": "California", "zipcode": 10021, "country": "United States of America", "cuisineType": “Yummy”, “priceRange”: 3, “phoneNumber”: 123456789, “openHours”: “10 am”, “closingHours” : “3pm”, "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", “zipcode”: “zipcode is required”, "name": "Name must be less than 50 characters", "description": "Description is required", "price": "Price range 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", "statusCode": 404 }
-
Deletes an existing restaurant.
-
Require Authentication: true
-
Require proper authorization: Restaurant must belong to the current user
-
Request
- Method: DELETE
- URL: /api/restaurants/:restaurantId
- Body: none
-
Successful Response
-
Status Code: 200
-
Headers:
- Content-Type: application/json
-
Body:
{ "message": "Successfully deleted", "statusCode": 200 }
-
-
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", "statusCode": 404 }
-
Return all the reservations that the current user has made.
-
Require Authentication: true
-
Request
- Method: GET
- URL: /api/user/reservations
- Body: none
-
Successful Response
-
Status Code: 200
-
Headers:
- Content-Type: application/json
-
Body:
{ "Reservations": [ { "id": 1, "restaurantId": 1, "Restaurant": { "id": 1, "ownerId": 1, "restaurauntName": "Apple Academy", "coverImage": "www.photo.example", "address": "123 Disney Lane", "city": "San Francisco", "state": "California", "zipcode": 10021, "country": "United States of America", "cuisineType": “Yummy”, “priceRange”: 3, “phoneNumber”: 123456789, “openHours”: “10 am”, “closingHours” : “3pm”, "createdAt": "2021-11-19 20:39:36", "updatedAt": "2021-11-19 20:39:36", }, "userId": 2, "reservationTime": "2021-11-19 20:39:36", "createdAt": "2021-11-19 20:39:36", "updatedAt": "2021-11-19 20:39:36" } ] }
-
Return all the reservations for a restaurant specified by id.
-
Require Authentication: true
-
Request
- Method: GET
- URL: /api/restaurant/:restaurantId/
- Body: none
-
Successful Response: If you ARE NOT the owner of the restaurant.
-
Status Code: 200
-
Headers:
- Content-Type: application/json
-
Body:
{ "Reservations": [ { "restaurantId": 1, "reservationId": 1, "reservationTime": "2021-11-19 20:30:00", }, { "restaurantId": 1, "reservationId": 2, "reservationTime": "2021-11-19 20:00:00", } ] }
-
-
Successful Response: If you ARE the owner of the restaurant.
-
Status Code: 200
-
Headers:
- Content-Type: application/json
-
Body:
{ "Reservations": [ { "id": 1, "restaurantId": 1, "userId": 2,
-
"User": { "id": 2, "firstName": "John", "lastName": "Smith" “phoneNumber”: 1234567891,
},
“numberOfPeople”: 3, "reservationTime": "2021-11-19 20:30:00", “status”: “confirmed”, “notes”: “this is my birthday, please sing”, "createdAt": "2021-11-19 20:30:36", "updatedAt": "2021-11-19 20:30: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", "statusCode": 404 }
-
Create and return a new reservation from a restaurant specified by id.
- Require Authentication: true
- Require proper authorization: Restaurant must NOT belong to the current user
- Request
-
Method: POST
-
URL: /api/restaurant/:restaurantId/
-
Body:
{
-
“numberOfPeople”: 3 “notes”: “this is my birthday, please sing” "reservationTime": "2021-11-19 20:30:00", }
```
- Successful Response
-
Status Code: 200
-
Headers:
- Content-Type: application/json
-
Body:
{ "id": 1, "restaurantId": 1, "userId": 2,
-
“numberOfPeople”: 3, "reservationTime": "2021-11-19 20:30:00", “status”: “confirmed”, “notes”: “this is my birthday, please sing”, "createdAt": "2021-11-19 20:30:36", "updatedAt": "2021-11-19 20:30:36"
}
```
-
Error response: Body validation errors
-
Status Code: 400
-
Headers:
- Content-Type: application/json
-
Body:
{ "message": "Validation error", "statusCode": 400, "errors": { "reservationTime": "reservation time cannot be in the past" } }
-
-
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", "statusCode": 404 }
-
-
Error response: Reservation conflict
-
Status Code: 403
-
Headers:
- Content-Type: application/json
-
Body:
{ "message": "Sorry, this restaurant is already booked to capacity for the specified time- try a later time or another date.", "statusCode": 403, "errors": { "reservationTime": "This choice conflicts with existing reservations", “numberOfPeople” : “This restaurant does not have enough seats at that time” } }
-
Update and return an existing reservation.
- Require Authentication: true
- Require proper authorization: Reservation must belong to the current user
- Request
-
Method: PUT
-
URL: /api/restaurant/:restaurantId/
-
Headers:
- Content-Type: application/json
-
Body:
{
-
- Successful Response
-
Status Code: 200
-
Headers:
- Content-Type: application/json
-
Body:
{ "id": 1, "restaurantId": 1, "userId": 2, “numberOfPeople”: 4,
-
“notes”: “this is my friend’s birthday, please don’t sing” "reservationTime": "2021-11-19 20:00:00", "createdAt": "2021-11-19 20:39:36", "updatedAt": "2021-11-19 20:39:36" } ```
-
Error response: Couldn't find a Reservation with the specified id
-
Status Code: 404
-
Headers:
- Content-Type: application/json
-
Body:
{ "message": "Reservation couldn't be found", "statusCode": 404 }
-
-
Error response: Can't edit a reservation that's past the reservation date time
-
Status Code: 403
-
Headers:
- Content-Type: application/json
-
Body:
{ "message": "Past reservations can't be modified", "statusCode": 403 }
-
-
Error response: Reservation conflict
-
Status Code: 403
-
Headers:
- Content-Type: application/json
-
Body:
{ "message": "Sorry, this restaurant is already booked to capacity for the specified time- try a later time or another date.", "statusCode": 403, "errors": { "reservationTime": "This choice conflicts with existing reservations", “numberOfPeople” : “This restaurant does not have enough seats at that time” } }
-
Delete an existing reservation.
-
Require Authentication: true
-
Require proper authorization: Reservation must belong to the current user or the Restaurant must belong to the current user
-
Request
- Method: DELETE
- URL: /api/reservations/:reservationId
- Body: none
-
Successful Response
-
Status Code: 200
-
Headers:
- Content-Type: application/json
-
Body:
{ "message": "Successfully deleted", "statusCode": 200 }
-
-
Error response: Couldn't find a Reservation with the specified id
-
Status Code: 404
-
Headers:
- Content-Type: application/json
-
Body:
{ "message": "Reservation couldn't be found", "statusCode": 404 }
-
-
Error response: Reservations that have been started or are in the past can't be deleted
-
Status Code: 403
-
Headers:
- Content-Type: application/json
-
Body:
{ "message": "Reservations that have been started or are in the past can't be deleted", "statusCode": 403 }
-
Favorites:
Adds a restaurant to the user’s list of favorite restaurants
Require Authentication: True Require proper authorization: User must be logged in to like and save a restaurant Request Method: POST URL: /api/user/:userId/favorites Headers: Content-Type: application/json Body: { restaurantId: 1 } Successful Response Status Code: 200 Headers: Content-type: application/json Body: { id: 1 userId: 1 restaurantId: 1 } Error Response: The user or restaurant with the provided ID does not exist Status Code: 404 Headers: Content-Type: application/json Body: { “Message”: “Restaurant not found”, “statusCode”: 404 } Error Response: The restaurant is already in the user’s list of favorites Status Code: 409 Headers: Content-Type: application/json Body: { “Message”: “Restarant already exists in user’s list of favorites” “statusCode”: 409 }
Returns a list of the user’s favorite restaurants Require Authentication: True Request Method: GET URL: /api/users/:userId/favorites Body: none Successful Response Status Code: 200 Headers: Content-Type: application/json Body: ((((IDK GUYS THIS MIGHT BE WRONG SYNTAX))) { 1:{ “userId”: 1, “restaurantId”: 1 }, 2: { “userId”: 1, “restaurantId”: 2 } } Error Response: An existing user with the provided “User ID” was not found Status Code: 404 Headers: Content-Type: application/json Body: { “Message”: “User cound not be found”, “statusCode”: 404 }
Removes a restaurant from the user’s list of favorite restaurants Require Authentication: True Request Method: DELETE URL: /api/user/:userId/favorites/ Body: {“id”: 1} Successful Response Status Code: 200 Headers: Content-Type: application/json Body: { “Message”: “Successfully removed”, “statusCode”: 200 } Error Response: restaurant with provided ID does not exist Status Code: 404 Headers: Content-Type: application/json Body: { “Message”:”Restaurant couldn’t be found”, “statusCode”: 404 }
Reviews:
Allows a user to create a review for a restaurant