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

include tasks in view #1302

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/code_corps_web/views/task_list_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ defmodule CodeCorpsWeb.TaskListView do

has_one :project, type: "project", field: :project_id

has_many :tasks, serializer: CodeCorpsWeb.TaskView, identifiers: :always
has_many :tasks, serializer: CodeCorpsWeb.TaskIncludedView, identifiers: :always, include: true
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe better to call this TaskSlimView.

Copy link
Contributor

Choose a reason for hiding this comment

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

Not a bad idea. Ideally, I would love if we could just specify what to include and where.

Possibly even the Ember client would do it, so we don't have to worry about this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

kind of like graphql? I would love that. I worked on a project and eventually there was 5 different views for the same resource, each giving you a different subset of data. It was slightly hard to manage.

We implemented the request on the ember side, but eventually the logic got complex and the various views were easier to manage.

end
13 changes: 13 additions & 0 deletions lib/code_corps_web/views/task_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,16 @@ defmodule CodeCorpsWeb.TaskView do
status
end
end

defmodule CodeCorpsWeb.TaskIncludedView do
@moduledoc false
use CodeCorpsWeb, :view
use JaSerializer.PhoenixView

def type, do: "task"

attributes [
:archived, :body, :created_at, :created_from, :inserted_at, :markdown,
:modified_at, :modified_from, :number, :order, :status, :title, :updated_at
]
end
21 changes: 20 additions & 1 deletion test/lib/code_corps_web/views/task_list_view_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,26 @@ defmodule CodeCorpsWeb.TaskListViewTest do
},
"jsonapi" => %{
"version" => "1.0"
}
},
"included" => [%{
"attributes" => %{
"archived" => task.archived,
"body" => task.body,
"created-at" => task.created_at,
"created-from" => task.created_from,
"inserted-at" => task.inserted_at,
"markdown" => task.markdown,
"modified-at" => task.modified_at,
"modified-from" => task.modified_from,
"number" => task.number,
"order" => task.order,
"status" => task.status,
"title" => task.title,
"updated-at" => task.updated_at
},
"id" => task.id |> Integer.to_string,
"type" => "task"
}]
}

assert rendered_json == expected_json
Expand Down