Given four files RecipeController.java
, RecipeRepository.java
, RecipeService.java
and Recipe.java
.
The RecipeService
class has a variable named recipeBook
, which is a HashMap that holds Integer
s as keys and Recipe
objects as values. Initially, it contains data of 5 recipes.
-
Recipe.java
: TheRecipe
class should contain the following attributes.Attribute Type Description recipeId int An integer that represents the unique ID of the recipe recipeName String A string that represents the name of the recipe recipeType String A string that represents the type(veg or non-veg) of the recipe ingredients List A list of strings that represent the ingredients of the recipe. -
RecipeRepository.java
: Create an interface containing required methods. -
ReceoueService.java
: Update the service class with logic for managing recipe data. -
RecipeController.java
: Create the controller class to handle HTTP requests.
Implement the following APIs.
Returns a list of all recipes in the recipeBook
.
[
{
"recipeId": 1,
"recipeName": "Pasta",
"recipeType": "veg",
"ingredients": [
"pasta",
"tomatoes",
"olive oil",
"garlic",
"basil"
]
},
...
]
Creates a new recipe in the recipeBook. recipeId
is auto-incremented
{
"recipeName": "Pizza",
"recipeType": "veg",
"ingredients": ["pizza dough", "onions", "mozzarella cheese","vegetables", "tomato sauce"]
}
{
"recipeId": 6,
"recipeName": "Pizza",
"recipeType": "veg",
"ingredients": [
"pizza dough",
"onions",
"mozzarella cheese",
"vegetables",
"tomato sauce"
]
}
Returns a recipe based on a recipe ID. If the given recipe ID is not found in the recipeBook
, raise ResponseStatusException
with HttpStatus.NOT_FOUND
.
{
"recipeId": 5,
"recipeName": "Fish and Chips",
"recipeType": "non-veg",
"ingredients": [
"fish",
"potatoes",
"flour",
"oil",
"spices"
]
}
Updates the details of a recipe in the recipeBook based on the recipe ID. If the given recipe ID is not found in the recipeBook
, raise ResponseStatusException
with HttpStatus.NOT_FOUND
.
{
"recipeName": "Fish and Potato Chips",
"ingredients": ["fish","potatoes","flour","oil","spices","water"]
}
{
"recipeId": 5,
"recipeName": "Fish and Potato Chips",
"recipeType": "Non-veg",
"ingredients": [
"fish",
"potatoes",
"flour",
"oil",
"spices",
"water"
]
}
Deletes a recipe from the recipeBook based on the recipe ID. If the given recipe ID is not found in the recipeBook
, raise ResponseStatusException
with HttpStatus.NOT_FOUND
.
Do not modify the code in RecipeApplication.java