Skip to content

Conversation

snewcomer
Copy link
Contributor

@snewcomer snewcomer commented Oct 30, 2017

Ref #1139

This is a very initial commit using jsonapi. Can try it out by running category_view_test.exs.

Essentially, this lib gives us a show and index function for which we can call.

Couple of things.

  1. The jsonapi lib might need some TLC to make it easier to work with.
    2. We use dasherized plural types. The dasherized config is not working for relationships right now. Solved with master branch

TODO:

  • cleanup and w/ potentially abstractions for working with lib
  • Identify PR's to lib
  • move to separate view and perf test against category_view w/ ja_serializer

has_many :project_categories, serializer: CodeCorpsWeb.ProjectCategoryView, identifiers: :always
def fields, do: [:name, :slug, :description]
def type, do: "category"
def relationships, do: [project_categories: CodeCorpsWeb.ProjectCategoryView]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will also try includes for relationships once we figure out how to use this lib.


attributes [:name, :slug, :description]
def render("show.json-api", %{ data: category, conn: conn, params: params }) do
__MODULE__.show(category, conn, params)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

params is an unused arg to the show function. Candidate for a PR to the lib.

def show(%Conn{} = conn, %{"id" => id}) do
with %Category{} = category <- Category |> Repo.get(id) |> preload() do
conn |> render("show.json-api", data: category)
conn |> render(CodeCorpsWeb.CategoryView, "show.json-api", %{ data: category, conn: conn, params: id })
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 wonder if we can just call the show action provided by the jsonapi lib instead of calling render....?

Copy link
Contributor

Choose a reason for hiding this comment

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

Seems plausible. Have you tried this?

@snewcomer
Copy link
Contributor Author

beam-community/jsonapi#78

First step. Unless my understanding is off, I am not sure if the lib could be improved for handling relationships. It seems like it requires preloading all relationships down the tree when. So for example, serializing project-category data, we only want to ask for the project_category_id from the category data instead of walking down the relationship tree.

Lmk if anybody sees it otherwise.

@snewcomer
Copy link
Contributor Author

Based on some of the perf findings with lots of tasks for a task_list view shown in the issue, was given the green light to work on includes with ja_serializer. I'll open in another PR.

@snewcomer snewcomer closed this Nov 2, 2017
@joshsmith joshsmith deleted the jsonapi branch November 3, 2017 06:55
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.

2 participants