Skip to content

Commit

Permalink
set up rating update function and update method on backend
Browse files Browse the repository at this point in the history
  • Loading branch information
mykovasyl committed Mar 22, 2023
1 parent d1f50ad commit 5845b80
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 5 deletions.
3 changes: 3 additions & 0 deletions .byebug_history
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
exit
params[:rating]
params
q
recipe
recipe.update({ingredients: params[:ingredients]})
Expand Down
4 changes: 3 additions & 1 deletion app/controllers/recipes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ def create
end

def update
recipe = Recipe.update!(update_recipe_params)
recipe_to_update = find_recipe
recipe_to_update.update!(update_recipe_params)
render json: recipe, status: :accepted
end

def destroy
Expand Down
2 changes: 1 addition & 1 deletion app/serializers/recipe_serializer.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
class RecipeSerializer < ActiveModel::Serializer
attributes :id, :title, :readyIn, :image, :summary, :instructions, :ingredients, :sourceURL, :user_id
attributes :id, :title, :readyIn, :image, :summary, :instructions, :ingredients, :sourceURL, :user_id, :rating
end
2 changes: 1 addition & 1 deletion client/src/components/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ function App() {
fetch(`/recipes/${recipe.id}`, {
method: "PATCH",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(recipe.rating),
body: JSON.stringify({ rating: recipe.rating }),
});
}

Expand Down
4 changes: 2 additions & 2 deletions client/src/components/Recipe.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ function Recipe({ recipe }) {
handleAddRecipe,
handleUpdateRecipe,
} = useContext(UserContext);
const [ratingValue, setRatingValue] = useState(0);
const {
title,
readyIn,
Expand All @@ -35,6 +34,7 @@ function Recipe({ recipe }) {
user_id = null,
id = null,
} = recipe;
const [ratingValue, setRatingValue] = useState(rating);

const mappedIngredients = ingredients.map((ingredient) => (
<li key={ingredient}>{ingredient}</li>
Expand Down Expand Up @@ -84,7 +84,7 @@ function Recipe({ recipe }) {
{user_id ? (
<Rating
name='simple-controlled'
value={rating}
value={ratingValue}
precision={0.5}
onChange={(event, newRating) => {
setRatingValue(newRating);
Expand Down

0 comments on commit 5845b80

Please sign in to comment.