Skip to content
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

Conversation

landongrindheim
Copy link
Contributor

@landongrindheim landongrindheim commented Oct 2, 2017

Remove SkillController's reliance on JaResource/Canary.

References

Closes #903

Progress on: #864 (working toward closing this one!)

def model, do: CodeCorps.Skill
@spec index(Conn.t, map) :: Conn.t
def index(%Conn{} = conn, %{} = params) do
with skills <- Skill
Copy link
Contributor Author

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 😄

Copy link
Contributor

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

@landongrindheim
Copy link
Contributor Author

landongrindheim commented Oct 3, 2017

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

Copy link
Contributor

@begedin begedin left a 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.

end

@spec changeset(CodeCorps.Skill.t, map) :: Ecto.Changeset.t
defp changeset(struct, params \\ %{}) do
Copy link
Contributor

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
Copy link
Contributor

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

@landongrindheim
Copy link
Contributor Author

@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

Copy link
Contributor

@begedin begedin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work 👍

@begedin begedin merged commit 159c8ec into code-corps:develop Oct 3, 2017
@landongrindheim landongrindheim deleted the 903-remove-ja-resource-from-skill-controller branch October 10, 2017 08:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants