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:

Popular Pragmatic topics Top

kuroneko
Whilst the author has been careful to provide exact results for the tests elsewhere in the book (such as surds with the transformation te...
New
conradwt
First, the code resources: Page 237: rumbl_umbrella/apps/rumbl/mix.exs Note: That this file is missing. Page 238: rumbl_umbrella/app...
New
New
patoncrispy
I’m new to Rust and am using this book to learn more as well as to feed my interest in game dev. I’ve just finished the flappy dragon exa...
New
jskubick
I think I might have found a problem involving SwitchCompat, thumbTint, and trackTint. As entered, the SwitchCompat changes color to hol...
New
jskubick
I’m under the impression that when the reader gets to page 136 (“View Data with the Database Inspector”), the code SHOULD be able to buil...
New
Charles
In general, the book isn’t yet updated for Phoenix version 1.6. On page 18 of the book, the authors indicate that an auto generated of ro...
New
AufHe
I’m a newbie to Rails 7 and have hit an issue with the bin/Dev script mentioned on pages 112-113. Iteration A1 - Seeing the list of prod...
New
s2k
Hi all, currently I wonder how the Tailwind colours work (or don’t work). For example, in app/views/layouts/application.html.erb I have...
New
davetron5000
Hello faithful readers! If you have tried to follow along in the book, you are asked to start up the dev environment via dx/build and ar...
New

Other popular topics Top

AstonJ
A thread that every forum needs! Simply post a link to a track on YouTube (or SoundCloud or Vimeo amongst others!) on a separate line an...
New
brentjanderson
Bought the Moonlander mechanical keyboard. Cherry Brown MX switches. Arms and wrists have been hurting enough that it’s time I did someth...
New
DevotionGeo
I know that -t flag is used along with -i flag for getting an interactive shell. But I cannot digest what the man page for docker run com...
New
New
New
wmnnd
Here’s the story how one of the world’s first production deployments of LiveView came to be - and how trying to improve it almost caused ...
New
gagan7995
API 4 Path: /user/following/ Method: GET Description: Returns the list of all names of people whom the user follows Response [ { ...
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
PragmaticBookshelf
Author Spotlight James Stanier @jstanier James Stanier, author of Effective Remote Work , discusses how to rethink the office as we e...
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

Latest in PragProg

View all threads ❯