At page 47, I run into a confusing part:
Excerpt from the page
With our user in place, let’s define our Accounts context. We will add a couple
of functions which will allow user account fetching. Let’s create a new file in
lib/rumbl/accounts.ex and key this in:
controllers_views_templates/listings/rumbl/lib/rumbl/accounts.ex
Line 1 defmodule Rumbl.Accounts do
- @moduledoc """
- The Accounts context.
- """
5
- alias Rumbl.Accounts.User
-
- def list_users do
- [
10 %User{id: "1", name: "José", username: "josevalim"},
- %User{id: "2", name: "Bruce", username: "redrapids"},
- %User{id: "3", name: "Chris", username: "chrismccord"}
- ]
- end
15
- def get_user(id) do
- Enum.find(list_users(), fn map -> map.id == id end)
- end
-
20 def get_user_by(params) do
- Enum.find(list_users(), fn map ->
- Enum.all?(params, fn {key, val} -> Map.get(map, key) == val end)
- end)
- end
25 end
Isn’t this suppose to be?
lib/rumbl/accounts.ex and key this in:
defmodule Rumbl.Accounts do
@moduledoc """
The accounts context
"""
alias Rumbl.Accounts.User
end
So what do I do with this part?
controllers_views_templates/listings/rumbl/lib/rumbl/accounts.ex
def list_users do
%User{id: "1", name: "Jose", username: "josevalim"},
%User{id: "2", name: "Bruce", username: "redrapids"},
%User{id: "3", name: "Chris", username: "chrismccord"}
end
def get_user(id) do
Enum.find(list_users(), fn map -> map.id == id end)
end
def get_user_by(params) do
Enum.find(list_users(), fn map ->
Enum.all?(params, fn {key, val} -> Map.get(map, key) == val end)
end)
end
Thank in advance if you can shed some light over this