Skip to content
This repository was archived by the owner on Jul 24, 2023. It is now read-only.

Refactor Recipes and Recipe creation#103

Open
tgomezzzz wants to merge 5 commits into
scale-recipesfrom
refactor-recipes
Open

Refactor Recipes and Recipe creation#103
tgomezzzz wants to merge 5 commits into
scale-recipesfrom
refactor-recipes

Conversation

@tgomezzzz

Copy link
Copy Markdown
Contributor

This PR refactors internal recipe creation, simplifying the recipe creation servlet. Previously, the doPost() method of NewRecipeServlet built a recipe Datastore entity by first extracting individual parameters with request.getParameter() and then setting the entity's properties. The PR scraps this approach, instead adding a Recipe constructor that takes in a Map, allowing one-line recipe creation using request.getParameterMap(). Instead of extracting each individual parameter from the request, the new constructor iterates over the key-value pairs in the map and stores the parameters in their corresponding Recipe fields. This iteration approach yields an advantage for the parameters that vary in number from recipe to recipe (tags, ingredients, equipment, and steps.) The servlet no longer needs to extract these parameters in the getParameters() method, which required a while loop to get the unknown number of each parameter. Since the new constructor iterates over every key-value pair, these parameters are simply added to their corresponding Recipe field collections as they're encountered. Once the iteration finishes, the constructor builds a Datastore entity from the parameters it just stored in its own Recipe object.

The PR also adjusts how tags, ingredients, equipment, and steps are stored in Datastore. Because these parameters were previously extracted with getParameters(), which returned a Collection of EmbeddedEntities, they were all wrapped in EmbeddedEntities in Datastore. Now that getParameters() is no longer used, this adds an unnecessary layer of complexity when saving recipes to Datastore and retrieving them from Datastore. This PR changes tags, equipment, and steps to be stored as a Collection of strings, while ingredients remain EmbeddedEntities to account for their additional properties. This allowed me to remove redundant helper methods that converted a Collection of EmbeddedEntities into tags, ingredients, equipment, and steps, as well as the entire Step class, which in retrospect served no real purpose.

@tgomezzzz
tgomezzzz requested review from Rmoneygit and angplee August 5, 2020 22:15
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants