Skip to content

Commit 3badf8a

Browse files
committed
include tasks in view
1 parent 44e53c1 commit 3badf8a

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed

lib/code_corps_web/views/task_list_view.ex

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ defmodule CodeCorpsWeb.TaskListView do
77

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

10-
has_many :tasks, serializer: CodeCorpsWeb.TaskView, identifiers: :always
10+
has_many :tasks, serializer: CodeCorpsWeb.TaskIncludedView, identifiers: :always, include: true
1111
end

lib/code_corps_web/views/task_view.ex

+12
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,15 @@ defmodule CodeCorpsWeb.TaskView do
3737
status
3838
end
3939
end
40+
41+
defmodule CodeCorpsWeb.TaskIncludedView do
42+
@moduledoc false
43+
use CodeCorpsWeb, :view
44+
use JaSerializer.PhoenixView
45+
def type, do: "task"
46+
47+
attributes [
48+
:archived, :body, :created_at, :created_from, :inserted_at, :markdown,
49+
:modified_at, :modified_from, :number, :order, :status, :title, :updated_at
50+
]
51+
end

test/lib/code_corps_web/views/task_list_view_test.exs

+20-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,26 @@ defmodule CodeCorpsWeb.TaskListViewTest do
3939
},
4040
"jsonapi" => %{
4141
"version" => "1.0"
42-
}
42+
},
43+
"included" => [%{
44+
"attributes" => %{
45+
"archived" => task.archived,
46+
"body" => task.body,
47+
"created-at" => task.created_at,
48+
"created-from" => task.created_from,
49+
"inserted-at" => task.inserted_at,
50+
"markdown" => task.markdown,
51+
"modified-at" => task.modified_at,
52+
"modified-from" => task.modified_from,
53+
"number" => task.number,
54+
"order" => task.order,
55+
"status" => task.status,
56+
"title" => task.title,
57+
"updated-at" => task.updated_at
58+
},
59+
"id" => task.id |> Integer.to_string,
60+
"type" => "task"
61+
}]
4362
}
4463

4564
assert rendered_json == expected_json

0 commit comments

Comments
 (0)