Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dt search #25

Closed
wants to merge 20 commits into from
Closed

Dt search #25

wants to merge 20 commits into from

Conversation

DavidTTran
Copy link
Collaborator

@DavidTTran DavidTTran commented May 30, 2020

Completed:

  • Recipe index pictures/titles are links to their show page
  • Search functionality moved to root path, only available after a user logs in
  • Sad paths for search function
    • No provided/conflicting params generates 10 random recipes
    • Provides up to 10 recipes

Refactor:

  • Moved Spoonacular request/response into SpoonacularService
  • Recipes are instantiated as a Recipe PORO
    • with @id, @title, @image, @ingredients, @instructions, @time, @nutrition

@DavidTTran DavidTTran removed a link to an issue May 30, 2020
This was linked to issues May 30, 2020
@DavidTTran DavidTTran removed a link to an issue May 30, 2020
Copy link
Owner

@alex-latham alex-latham left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good, but the requires in RecipesController and poros/recipe.rb go against Rails' 'convention over configuration' philosophy. There are a couple ways to structure these POROs in a way that Rails will know about them without having a require -- the simplest being relocate the POROs folder to app/poros and then removing the require(_relative)s RecipesController and Recipe. Another alternative would be to rename the poros folder to spoonacular, and then wrapping the PORO classes inside in a Spoonacular module so you can call Spoonacular::Recipe from the RecipesController without the require. Wrapping them in a module also puts recipe_ingredients/instructions/nutrition into the same scope so the require_relatives would become unnecessary. Brownfield came with an example of the latter structure with its models/you_tube POROs folder/module.

Sorry for the wall of text! I pushed up a branch agl_dt_search with a proof of concept if you are interested in taking a gander.

Recipe.new(recipe_json)
end
if @recipes.empty?
flash[:error] = "Sorry, we couldn't find any recipes matching your
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this part! haha

@@ -0,0 +1,24 @@
class RecipesController < ApplicationController
def index
recipes = SpoonacularService.new(search_params).parse_recipes
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably a good place for a refactor later down the line.

@@ -0,0 +1,33 @@
class Recipe
attr_reader :id,
Copy link
Collaborator

@mikez321 mikez321 May 30, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we using this ID for something later? Do we need to expose it? - Nevermind
Oh... yeah, for the ID in the recipe show

type: @params['type'],
minCalories: 0, minCholesterol: 0,
minFat: 0, minProtein: 0, minCarbs: 0, minSugar: 0, minSodium: 0,
number: 10, sort: 'random' }.compact
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getting rid of nils, nice!

<%= text_field_tag :ingredients, nil, placeholder: "Enter your ingredients:" %><br>
<h2>DIET</h2>
<%= check_box_tag 'diet[]', 'vegetarian' %>
<%= label_tag :vegetarian %><br>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a heads up... I think we'll have pretty much all of these in a container of some sort and won't need the
tags.... I think...

Copy link
Owner

@alex-latham alex-latham left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Solid work. Everything looks good to me.

Copy link
Collaborator

@mikez321 mikez321 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great David! Thanks for all your work on this and answering my questions along the way.

@DavidTTran DavidTTran closed this May 30, 2020
@DavidTTran DavidTTran deleted the dt-search branch May 31, 2020 00:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Recipe Index Page Sad Path Ingredients Filter Results Visitors must log in to access app
3 participants