-
Notifications
You must be signed in to change notification settings - Fork 86
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove JaResource/Canary from SkillController #1001
Remove JaResource/Canary from SkillController #1001
Conversation
def model, do: CodeCorps.Skill | ||
@spec index(Conn.t, map) :: Conn.t | ||
def index(%Conn{} = conn, %{} = params) do | ||
with skills <- Skill |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn't able to find a community standard for a with
clause which uses piping. This felt right, but I'm open to other suggestions 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Simplest trick I can think off would be to add a defp load_skills(%{} = params)
into the controller and call
with skills <- params |> load_skills() do
I also considered these options: # 1)
def index(%Conn{} = conn, %{} = params) do
with skills <- Skill |> id_filter(params) |> title_filter(params) |> limit_filter(params) |> Repo.all do
conn |> render("index.json-api", data: skills)
end
end
# 2)
def index(%Conn{} = conn, %{} = params) do
with skills <- Skill
|> id_filter(params)
|> title_filter(params)
|> limit_filter(params)
|> Repo.all
do
conn |> render("index.json-api", data: skills)
end
end
# 3)
def index(%Conn{} = conn, %{} = params) do
with skills <- Skill
|> Query.id_filter(params)
|> Query.title_filter(params)
|> Query.limit_filter(params)
|> Repo.all,
do: conn |> render("index.json-api", data: skills)
end
# 4)
def index(%Conn{} = conn, %{} = params) do
with skills <-
Skill
|> Query.id_filter(params)
|> Query.title_filter(params)
|> Query.limit_filter(params)
|> Repo.all,
do: conn |> render("index.json-api", data: skills)
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall looks good, just a couple minor tweaks to make it easier to read.
lib/code_corps/model/skill.ex
Outdated
end | ||
|
||
@spec changeset(CodeCorps.Skill.t, map) :: Ecto.Changeset.t | ||
defp changeset(struct, params \\ %{}) do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this just adds an extra layer we don't really need. I see why you did it, but I think it would be preferable to revert on this and instead just call Skill.changeset
from the controller.
def model, do: CodeCorps.Skill | ||
@spec index(Conn.t, map) :: Conn.t | ||
def index(%Conn{} = conn, %{} = params) do | ||
with skills <- Skill |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Simplest trick I can think off would be to add a defp load_skills(%{} = params)
into the controller and call
with skills <- params |> load_skills() do
@begedin Thanks for the feedback! Can you let me know if this lines up with what you're thinking? If so, I'll squash the commits |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work 👍
Remove SkillController's reliance on JaResource/Canary.
References
Closes #903
Progress on: #864 (working toward closing this one!)