Skip to content

Commit

Permalink
Added code to delete the recipe
Browse files Browse the repository at this point in the history
  • Loading branch information
qtsathish committed Nov 19, 2021
1 parent eee927b commit f65ac42
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
14 changes: 14 additions & 0 deletions InstaCook/resources/recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,19 @@ def put(self, recipe_id):
recipe.description = data['description']
return recipe.data, HTTPStatus.OK

def delete(self, recipe_id):
"""
Delete implementation of the Recipe
:param recipe_id: id of the recipe to be deleted
:return: NO_CONTENT if the Recipe is deleted and NOT_FOUND if the recipe is not found
"""
recipe = self.find_recipe(recipe_id)
if recipe is None:
return {'message': 'recipe not found'}, HTTPStatus.NOT_FOUND
recipe_list.remove(recipe)
return {}, HTTPStatus.NO_CONTENT

@staticmethod
def find_recipe(recipe_id) -> Recipe:
"""
Expand All @@ -86,6 +99,7 @@ class RecipePublishResource(Resource):
"""
This class represents a Rest Resource to Publish and UnPublish Recipes
"""

def put(self, recipe_id):
"""
This method is used to publish the Recipe
Expand Down
36 changes: 36 additions & 0 deletions Postman/InstaCook.postman_collection.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,24 @@
},
"response": []
},
{
"name": "Delete the Recipe",
"request": {
"method": "DELETE",
"header": [],
"url": {
"raw": "{{base_url}}/recipes/1",
"host": [
"{{base_url}}"
],
"path": [
"recipes",
"1"
]
}
},
"response": []
},
{
"name": "Get Specific Recipe",
"request": {
Expand Down Expand Up @@ -213,6 +231,24 @@
}
},
"response": []
},
{
"name": "Delete Non Existing Recipe",
"request": {
"method": "DELETE",
"header": [],
"url": {
"raw": "{{base_url}}/recipes/99999",
"host": [
"{{base_url}}"
],
"path": [
"recipes",
"99999"
]
}
},
"response": []
}
],
"event": [
Expand Down

0 comments on commit f65ac42

Please sign in to comment.