-
Notifications
You must be signed in to change notification settings - Fork 0
API ROUTES
Creates a new user, logs them in as the current user, and returns the current users information.
- Request
- Method: Post
- URL: /api/auth/signup
- Headers:
- Content-Type: application/json
- Body:
{ "email": "[email protected]", "first_name": "Tester", "last_name": "McTesty", "bio": "I'm a test bio", "profile_pic": "http://testURL.com", "password": "password" }
- Successful Response
- Status Code: 200
- Headers:
- Content-Type: application/json
- Body:
{
"id": 14,
"bio": "I'm a test bio",
"email": "[email protected]",
"first_name": "Tester",
"last_name": "McTesty",
"profile_pic": "http://testURL.com"
}
- Error Response: Email already in use
- Status Code: 401
- Headers
- Content-Type: application/json
- Body:
{
"email": [
"Email address is already in use."
]
}
- Error Response: Body validation Errors
- Status Code: 401
- Headers
- Content-Type: application/json
- Body
{
"bio": [
"This field is required."
],
"email": [
"This field is required."
],
"first_name": [
"This field is required."
],
"last_name": [
"This field is required."
],
"password": [
"This field is required."
],
"profile_pic": [
"This field is required."
]
}
Logs in a User when provided with valid credentials and returns the users information
- Request
- Method: POST
- URL: /api/auth/login
- Headers:
- Content-Type: application/json
- Body:
{ "email": "[email protected], "password": "password" }
- Successful Response
- Status Code: 200
- Headers:
- Content-Type: application/json
- Body
{
"id": 14,
"bio": "I'm a test bio",
"email": "[email protected]",
"first_name": "Tester",
"last_name": "McTesty",
"profile_pic": "http://testURL.com"
}
- Error Response: Body Validation Errors
- Status Code: 401
- Headers:
- Content-Type: application/json
- Body
{
"email": [
"This field is required."
],
"password": [
"This field is required."
]
}
- Error Response: Invalid email
- Status Code: 401
- Headers:
- Content-Type: application/json
- Body:
{
"email": "[email protected]",
"password": "wrongPassword"
}
- Error Response: Invalid Password
- Status Code: 401
- Headers:
- Content-Type: application/json
- Body:
{
"password": [
"Password was incorrect."
]
}
Logs out the current user and returns a logout message
- Request
- Method: GET
- URL: /api/auth/logout
- Successful Response
- Status Code: 200
- Body:
{
"message": "User logged out"
}
Authenticates the current user with valid credentials and returns the current user's information.
- Request
- Method: GET
- URL: /api/auth
- Successful Response
- Status Code: 200
- Headers:
- Content-Type: application/json
- Body
{
"bio": "I'm a test bio",
"email": "[email protected]",
"first_name": "Tester",
"id": 14,
"last_name": "McTesty",
"profile_pic": "http://testURL.com"
}
- Error Response: Invalid User
- Status Code: 401
- Headers:
- Content-Type: application/json
- Body:
{
"errors": {
"message": "Unauthorized"
}
}
Takes in user input, creates a new recipe and returns the details of that new recipe
- Require Authentication: True
- Request
- Method: POST
- URL: /api/recipes
- Body:
{
"category_id": 1,
"title": "The Testiest Recipe",
"description": "This is the testiest recipe in all of britania",
"servings": "10",
"prep_time": 100,
"cook_time": 300,
"preview_image": "http://theTestiestImage.com",
"ingredients": {
"1": {
"ingredient": "potatoe",
"ingredient_quantity": 7,
"ingredient_measurement_id": 3
},
... Rest of Ingredients
},
"steps": {
"1": {
"step_number": 1,
"description": "first, cook the potatoes, then cook the tomatoes"
},
... Rest of Steps
}
}
- Successful Response
- Status Code: 200
- Header:
- Content-Type: application/json
- Body
{
"category_id": 1,
"cook_time": 300,
"created_at": "Tue, 16 Jan 2024 01:25:15 GMT",
"description": "This is the testiest recipe in all of britania",
"id": 37,
"owner": {
"bio": "I'm a test bio",
"email": "[email protected]",
"first_name": "Tester",
"id": 14,
"last_name": "McTesty",
"profile_pic": "http://testURL.com"
},
"owner_id": 14,
"prep_time": 100,
"preview_image": "http://theTestiestImage.com",
"servings": 10.0,
"title": "The Testiest Recipe"
}
- Error Response: Body Validations
- Status Code: 400
- Headers:
- Content-Type: application/json
- Body
{
"errors": {
"category_id": [
"This field is required."
],
"cook_time": [
"This field is required."
],
"description": [
"This field is required."
],
"ingredient": [
"This field is required."
],
"ingredient_quantity": [
"This field is required."
],
"measurement_id": [
"This field is required."
],
"prep_time": [
"This field is required."
],
"preview_image": [
"This field is required."
],
"servings": [
"This field is required."
],
"step_description": [
"This field is required."
],
"step_number": [
"This field is required."
],
"title": [
"This field is required."
]
}
}
Queries the database for all of the recipes and returns an an object organized by category id's and an array of recipes in that category
-
User Authentication: False
-
Request
- Method: GET
- URL: /api/recipes
- Body: None
-
Successful Response
- Status Code: 200
- Headers:
- Content-Type: application/json
- Body
{
"1": [
{
"all_ratings": 4,
"avg_rating": 3.5,
"category_id": 1,
"cook_time": 1,
"created_at": "Tue, 08 Aug 2023 11:10:00 GMT",
"description": "A classic and tasty guacamole served with crisp tortilla chips.",
"id": 13,
"owner": {
"bio": "I'm Marnie and I'd love to have a good tasting meal",
"email": "[email protected]",
"first_name": "marnie",
"id": 2,
"last_name": "tester",
"profile_pic": "https://i.pinimg.com/474x/dd/94/3d/dd943d14b334896b33a8d3ba8e0cde05.jpg"
},
"owner_id": 2,
"prep_time": 15,
"preview_image": "https://thrivinghomeblog.com/wp-content/uploads/2022/01/Chips-and-Guacamole-3.jpg",
"ratings": [
{
"id": 32,
"rating": 5,
"recipe_id": 13,
"user_id": 3
},
... Rest of Ratings
],
"servings": 6.0,
"title": "Guacamole and Chips"
},
]
... Rest of Categories / Recipes
}
Returns all of the appropriate information for a single recipe, including associated reviews
-
User Authentication: False
-
Request
- Method: GET
- URL: /api/recipes/:recipeId
- Body: None
-
Successful Response:
- Status Code: 200
- Headers:
- Content-Type: application/json
- Body:
{
"id": 1,
"all_ratings": 4,
"avg_rating": 3.25,
"category_id": 2,
"cook_time": 40,
"created_at": "Sat, 13 Jan 2024 18:33:35 GMT",
"description": "Classic Italian pasta dish with rich meat sauce.",
"title": "Spaghetti Bolognese",
"owner_id": 3,
"prep_time": 20,
"servings": 4.0,
"preview_image": "https://www.thevegspace.co.uk/wp-content/uploads/2015/06/FV-Insta-3.jpg",
"owner": {
"bio": " I'm Bob the Builder and I can always go for a good snack",
"email": "[email protected]",
"first_name": "bobbie",
"id": 3,
"last_name": "builder",
"profile_pic": "https://avatars.githubusercontent.com/u/5268568?v=4"
},
"ingredients": {
"1": {
"id": 1,
"ingredient": "Spaghetti",
"ingredient_measurement_id": 8,
"ingredient_quantity": 300.0,
"recipe_id": 1
},
Rest of Ingredients...
},
"ratings": [
{
"id": 1,
"rating": 4,
"recipe_id": 1,
"user_id": 1
},
Rest of Reviews...
],
"reviews": [
{
"body": "Delicious dish! I loved it.",
"created_at": "Sat, 13 Jan 2024 18:33:35 GMT",
"edited": false,
"id": 1,
"name": "Demo Lition",
"private": false,
"recipe_id": 1,
"review_likes": {
"1": {
"bio": "My name is Demo-Lition and I'm really exicited to try new foods",
"email": "[email protected]",
"first_name": "Demo",
"id": 1,
"last_name": "lition",
"profile_pic": "https://cdn.pixabay.com/photo/2015/10/05/22/37/blank-profile-picture-973460_960_720.png"
},
... Rest of Review Likes
},
"updated_at": "Sat, 13 Jan 2024 18:33:35 GMT",
"user_id": 1
}
],
"steps": {
"1.0": {
"description": "Boil water and cook spaghetti according to package instructions.",
"id": 1,
"recipe_id": 1,
"step_number": 1.0
},
... Rest of Steps
}
Returns an object of all recipes owned by the user specified.
- User Authentication: False
- Request
- Method: GET
- URL: /api/users/:userId/recipes
- body: None
- Successful Response
- Status Code: 200
- Headers:
- Content-Type: application/json
- Body:
{
"owner": {
"bio": "My name is Demo-Lition and I'm really exicited to try new foods",
"email": "[email protected]",
"first_name": "Demo",
"id": 1,
"last_name": "lition",
"profile_pic": "https://cdn.pixabay.com/photo/2015/10/05/22/37/blank-profile-picture-973460_960_720.png"
},
"recipes": {
"3": {
"all_ratings": 7,
"avg_rating": 3.7142857142857144,
"category_id": 7,
"cook_time": 15,
"created_at": "Sat, 13 Jan 2024 18:33:35 GMT",
"description": "Quick and easy stir-fry with a variety of colorful vegetables.",
"id": 3,
"owner": {
"bio": "My name is Demo-Lition and I'm really exicited to try new foods",
"email": "[email protected]",
"first_name": "Demo",
"id": 1,
"last_name": "lition",
"profile_pic": "https://cdn.pixabay.com/photo/2015/10/05/22/37/blank-profile-picture-973460_960_720.png"
},
"owner_id": 1,
"prep_time": 10,
"preview_image": "https://hips.hearstapps.com/hmg-prod/images/veggie-stir-fry-1597687367.jpg",
"ratings": [
{
"id": 7,
"rating": 5,
"recipe_id": 3,
"user_id": 7
},
... Rest of Ratings
],
"servings": 3.0,
"title": "Vegetarian Stir-Fry"
},
... Rest of Recipes
}
}
Allows the owner of a recipe to delete it and return a success message
- User Authentication: True
- Request
- Method: DELETE
- URL: /api/recipes/:recipeId
- Body: None
- Successful Response
- Status Code: 200
- Body:
{
"message": "successful"
}
- Error Response: Not Owner
- Status Code 403
- Headers
- Content-Type: application/json
- Body
{
"error": "Unauthorized"
}
- Error Response: Recipe Not Found
- Status Code: 404
- Headers
- Content-Type: application/json
- Body
{
"error": "resource not found"
}
- User Authorization: True
- Request
- URL: /api/recipes/:recipeId/ratings
- Method: POST
- Headers
- Content-Type: application/json
- Body
{
"recipe_id": 1,
"user_id": 14,
"rating": 5
}
- Successful Response
- Status Code: 200
- Headers
- Content-Type: application/json
- Body
{
"id": 168,
"rating": 5,
"recipe_id": 1,
"user_id": 14
}
- User Authorization: True
- Request
- URL: /api/ratings/:ratingId
- Method: PUT
- Headers
- Content-Type: application/json
- Body
{
"recipe_id": 1,
"user_id": 14,
"rating": 1
}
- Successful Response
- Status Code: 200
- Headers
- Content-Type: application/json
- Body
{
"id": 168,
"rating": 1,
"recipe_id": 1,
"user_id": 14
}
- Error Response: Invalid Id
- Status Code: 404
- Headers
- Content-Type: application/json
- Body
{
"errors": "Rating not found"
}
-
User Authorization: True
-
Request
- URL: /api/ratings/:ratingId
- Method: DELETE
- Headers
- Content-Type: application/json
- Body: None
-
Successful Response
- Status Code: 200
- Headers
- Content-Type: application/json
- Body
{
"message": "successfully deleted"
}
- Error Response: Invalid Id
- Status Code: 404
- Headers
- Content-Type: application/json
- Body
{
"errors": "Rating not found"
}
- Error Response: Unauthorized
- Status Code: 401
- Headers
- Content-Type: application/json
- Body
{
"errors": "Unauthorized"
}