herminiotorres

herminiotorres

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.

Marked As Solved

SophieDeBenedetto

SophieDeBenedetto

Author of Programming Phoenix LiveView

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

Also Liked

SophieDeBenedetto

SophieDeBenedetto

Author of Programming Phoenix LiveView

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:

Where Next?

Popular Pragmatic Bookshelf topics Top

New
jeffmcompsci
Title: Design and Build Great Web APIs - typo “https://company-atk.herokuapp.com/2258ie4t68jv” (page 19, third bullet in URL list) Typo:...
New
mikecargal
Title: Hands-On Rust (Chapter 11: prefab) Just played a couple of amulet-less games. With a bit of debugging, I believe that your can_p...
New
joepstender
The generated iex result below should list products instead of product for the metadata. (page 67) iex&gt; product = %Product{} %Pento....
New
rmurray10127
Title: Intuitive Python: docker run… denied error (page 2) Attempted to run the docker command in both CLI and Powershell PS C:\Users\r...
New
brian-m-ops
#book-python-testing-with-pytest-second-edition Hi. Thanks for writing the book. I am just learning so this might just of been an issue ...
New
curtosis
Running mix deps.get in the sensor_hub directory fails with the following error: ** (Mix) No SSH public keys found in ~/.ssh. An ssh aut...
New
hazardco
On page 78 the following code appears: &lt;%= link_to ‘Destroy’, product, class: ‘hover:underline’, method: :delete, data: { confirm...
New
Keton
When running the program in chapter 8, “Implementing Combat”, the printout Health before attack was never printed so I assumed something ...
New
mcpierce
@mfazio23 I’ve applied the changes from Chapter 5 of the book and everything builds correctly and runs. But, when I try to start a game,...
New

Other popular topics Top

AstonJ
Or looking forward to? :nerd_face:
New
New
AstonJ
Continuing the discussion from Thinking about learning Crystal, let’s discuss - I was wondering which languages don’t GC - maybe we can c...
New
PragmaticBookshelf
Create efficient, elegant software tests in pytest, Python's most powerful testing framework. Brian Okken @brianokken Edited by Kat...
New
mafinar
This is going to be a long an frequently posted thread. While talking to a friend of mine who has taken data structure and algorithm cou...
New
AstonJ
If you get Can't find emacs in your PATH when trying to install Doom Emacs on your Mac you… just… need to install Emacs first! :lol: bre...
New
husaindevelop
Inside our android webview app, we are trying to paste the copied content from another app eg (notes) using navigator.clipboard.readtext ...
New
sir.laksmana_wenk
I’m able to do the “artistic” part of game-development; character designing/modeling, music, environment modeling, etc. However, I don’t...
New
AstonJ
This is cool! DEEPSEEK-V3 ON M4 MAC: BLAZING FAST INFERENCE ON APPLE SILICON We just witnessed something incredible: the largest open-s...
New
AstonJ
This is a very quick guide, you just need to: Download LM Studio: https://lmstudio.ai/ Click on search Type DeepSeek, then select the o...
New

Sub Categories: