         conn
         |> put_status(:created)
         |> put_resp_header("location", v1_meal_path(conn, :show, meal))
-        |> render("show.json", meal: Repo.preload(meal, [ingredients: [ingredient: [:process, :ingredientclass, components: [component: :unit]]]]))
+        |> render("show.json", meal: Repo.preload(meal, @preloads))
       {:error, changeset} ->
         conn
         |> put_status(:unprocessable_entity)


  def show(conn, %{"id" => id}) do
    meal = Repo.get!(Meal, id)
      |> Repo.preload([ingredients: [ingredient: [:process, :ingredientclass, components: [component: :unit]]]])
    render(conn, "show.json", meal: meal)
  end

  def update(conn, %{"id" => id, "meal" => meal_params}) do
    meal = Repo.get!(Meal, id)
    changeset = Meal.changeset(meal, meal_params)

    case Repo.update(changeset) do

  alias MealprepBackend.V1.Meal

  plug :scrub_params, "meal" when action in [:create, :update]

  @preloads [
    ingredients: [
      ingredient: [
        :process,
        :ingredientclass,
        components: [
          component: :unit
        ]
      ]
    ]
  ]

  def index(conn, _params) do
    meals = Repo.all(Meal)
