Skip to content

Commit

Permalink
reset task-list viwe
Browse files Browse the repository at this point in the history
  • Loading branch information
snewcomer committed Dec 12, 2017
1 parent 5dd7826 commit 8cafe65
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 19 deletions.
7 changes: 3 additions & 4 deletions lib/code_corps_web/controllers/task_list_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ defmodule CodeCorpsWeb.TaskListController do
use CodeCorpsWeb, :controller

alias CodeCorps.{Helpers.Query, TaskList}
alias CodeCorpsWeb.{TaskListView}

action_fallback CodeCorpsWeb.FallbackController
plug CodeCorpsWeb.Plug.DataToAttributes
Expand All @@ -19,13 +18,13 @@ defmodule CodeCorpsWeb.TaskListController do
|> Repo.all()
|> preload()

conn |> render(TaskListView, "index.json-api", %{data: task_lists, conn: conn})
conn |> render("index.json-api", data: task_lists)
end

@spec show(Conn.t, map) :: Conn.t
def show(%Conn{} = conn, %{"id" => id}) do
with %TaskList{} = task_list <- TaskList |> Repo.get(id) |> preload() do
conn |> render(TaskListView, "show.json-api", %{data: task_list, conn: conn, params: id})
conn |> render("show.json-api", data: task_list)
end
end

Expand All @@ -34,4 +33,4 @@ defmodule CodeCorpsWeb.TaskListController do
def preload(data) do
Repo.preload(data, @preloads)
end
end
end
20 changes: 5 additions & 15 deletions lib/code_corps_web/views/task_list_view.ex
Original file line number Diff line number Diff line change
@@ -1,21 +1,11 @@
defmodule CodeCorpsWeb.TaskListView do
@moduledoc false
use CodeCorpsWeb, :view
use JSONAPI.View, type: "task-list"
use JaSerializer.PhoenixView

alias CodeCorpsWeb.{ProjectView, TaskView}
attributes [:done, :inbox, :name, :order, :pull_requests, :inserted_at, :updated_at]

def render("index.json-api", %{data: task_list, conn: conn}) do
__MODULE__.index(task_list, conn, nil)
end
has_one :project, type: "project", field: :project_id

def render("show.json-api", %{data: task_list, conn: conn, params: params}) do
__MODULE__.show(task_list, conn, params)
end

def fields, do: [:done, :inbox, :name, :order, :pull_requests, :inserted_at, :updated_at]

# def relationships do
# [project: ProjectView, tasks: TaskView]
# end
end
has_many :tasks, serializer: CodeCorpsWeb.TaskView, identifiers: :always
end

0 comments on commit 8cafe65

Please sign in to comment.