Programming Phoenix LiveView - Version B5.0

On Chapter 3 - Page 78, the beginning of the page has this code here:

@doc """
 Maybe it is missing to put the Pento context before Catalog.Product.Query?
"""
defmodule Catalog.Product.Query do
  ...
  def base_product_query, do: Product
  
  def cheaper_than(query, price), do: from in query, where...
  
  def cheap_product_skus(price)
    base_product_query()
    |> chaper_than(price)
    |> skus
  end
  ...
end

And for the code almost to the bottom, has some typos. Like:

defmodule Pento.Catalog do
  alias Catalog.Product.Query
  alias Pento.Repo

  def run_query(query) do
    {:ok, list} = Repo.all(query)
    list
  end

  def send_sale_skus(query) do
    query
    |> Product.cheap_product_skus(25.00) # Typo: Query.cheap_product_skus(25.00)
    |> run_query
    |> Service.send_bargains # Question: the name of the module it is only Service?
  end
end

Also, for the next page 79, has more typos too, like:

defmodule Pento.Catalog do
  alias Catalog.Product.Query
  alias Pento.Repo

  @doc """
   For the Repo.all API, has only three options:
   1. Empty List without any items.
   2. List with one or more items.
   3. Query doesn't work and raise an error.
   """
  def run_query(query) do
    Repo.all(query)
  end

  def send_sale_skus(query) do
    query
    |> Product.cheap_product_skus(25.00) # Typo: Query.cheap_product_skus(25.00)
    |> run_query
  end

  def send_sale_skus(query)
    with {:ok, products} <- send_sale_skus(query), # this line of code here, never pattern matching
         {:ok, response} <- Service.send_bargains(products) do # when this line of code it fails? Returns as a tuple with {:error, reason} ?
      response
    else
       # if some error or cas doesn't pattern match in with conditions it will failure here a raise an error with unclause matching.
      {:error, reason} ->
        IO.puts "Error sending sale skus: #{reason}"
    end
  end
end

After words this is my feedback even these code as an example, and not intended to use. Besides, I use common comments as #, and some others I use @doc to get my point of view.

Thank you so much for sharing this feedback @herminiotorres! I’ve made some changes to fix the typo and to provide a better example of when to use with statements in your Phoenix context. You’ll find those changes in the next release :slight_smile: :slight_smile:

1 Like

On page 106, paragraph 2 has a typo, with two the:

render/1 function as part of the the assigns.

On page 90, last paragraph, the word the and list_products() has no space between them, like: thelist_products():

Here, it does so with the help oh thelist_products() function.

Thank you for catching these! We’ll fix them for the next release :slight_smile: