Skip to content

Commit

Permalink
Merge pull request #1012 from landongrindheim/910-remove-ja-resource-…
Browse files Browse the repository at this point in the history
…from-task-list-controller

Remove JaResource from TaskListController
  • Loading branch information
joshsmith committed Oct 4, 2017
2 parents 83e202c + 6727c0b commit e5d7b0e
Showing 1 changed file with 13 additions and 19 deletions.
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

0 comments on commit e5d7b0e

Please sign in to comment.