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 from TaskListController #1012

Merged
Changes from all commits
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
32 changes: 13 additions & 19 deletions lib/code_corps_web/controllers/task_list_controller.ex
Original file line number Diff line number Diff line change
@@ -1,33 +1,27 @@
defmodule CodeCorpsWeb.TaskListController do
use CodeCorpsWeb, :controller
use JaResource

import CodeCorps.Helpers.Query, only: [
project_filter: 2, sort_by_order: 1,
]

alias CodeCorps.TaskList

plug :load_resource, model: TaskList, only: [:show]
plug JaResource
action_fallback CodeCorpsWeb.FallbackController
plug CodeCorpsWeb.Plug.DataToAttributes
plug CodeCorpsWeb.Plug.IdsToIntegers

@spec model :: module
def model, do: CodeCorps.TaskList

def handle_index(conn, params) do
tasks = TaskList
|> project_filter(params)
|> sort_by_order
|> Repo.all()

conn
|> render("index.json-api", data: tasks)
@spec index(Conn.t, map) :: Conn.t
def index(%Conn{} = conn, %{} = params) do
with task_lists <- TaskList |> project_filter(params) |> sort_by_order() |> Repo.all do
conn |> render("index.json-api", data: task_lists)
end
end

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