Skip to content

Commit 723f977

Browse files
committed
Remove pagination from tasks
1 parent c4d9876 commit 723f977

2 files changed

Lines changed: 9 additions & 77 deletions

File tree

test/controllers/task_controller_test.exs

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -201,59 +201,4 @@ defmodule CodeCorps.TaskControllerTest do
201201
assert conn |> request_update |> json_response(403)
202202
end
203203
end
204-
205-
describe "pagination" do
206-
test "specifying a page size works", %{conn: conn} do
207-
project_1 = insert(:project)
208-
user = insert(:user)
209-
insert_list(3, :task, project: project_1, user: user)
210-
211-
path = conn |> task_path(:index)
212-
json =
213-
conn
214-
|> get(path, page: %{page_size: 2})
215-
|> json_response(200)
216-
217-
assert json["data"] |> Enum.count == 2
218-
end
219-
220-
test "specifying a page number works", %{conn: conn} do
221-
project_1 = insert(:project)
222-
user = insert(:user)
223-
224-
insert_list(2, :task, project: project_1, user: user)
225-
task_to_test = insert(:task, project: project_1, user: user)
226-
insert(:task, project: project_1, user: user)
227-
228-
path = conn |> task_path(:index)
229-
json =
230-
conn
231-
|> get(path, page: %{ page: 2, page_size: 2 })
232-
|> json_response(200)
233-
234-
[ %{"id" => id} | _ ] = json["data"]
235-
236-
assert String.to_integer(id) == task_to_test.id
237-
end
238-
239-
test "paginated results include a valid meta key", %{conn: conn} do
240-
project_1 = insert(:project)
241-
user = insert(:user)
242-
insert_list(6, :task, project: project_1, user: user)
243-
244-
meta = %{
245-
"total_records" => 6,
246-
"total_pages" => 3,
247-
"page_size" => 2,
248-
"current_page" => 1,
249-
}
250-
path = conn |> task_path(:index)
251-
json =
252-
conn
253-
|> get(path, page: %{ page_size: 2 })
254-
|> json_response(200)
255-
256-
assert json["meta"] == meta
257-
end
258-
end
259204
end

web/controllers/task_controller.ex

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,30 +14,17 @@ defmodule CodeCorps.TaskController do
1414
plug JaResource
1515

1616
def handle_index(conn, params) do
17-
page = Task
18-
|> project_filter(params)
19-
|> task_list_filter(params)
20-
|> task_type_filter(params)
21-
|> task_status_filter(params)
22-
|> sort_by_order
23-
|> Repo.paginate(params["page"] || %{})
24-
25-
# TODO: Once we are able to more easily add top-level meta
26-
# from within ja_resource or ja_serializer
27-
# we can split up all of this into
28-
# handle_index
29-
# handle_index_query
30-
# serialization_opts
31-
32-
meta = %{
33-
current_page: page.page_number,
34-
page_size: page.page_size,
35-
total_pages: page.total_pages,
36-
total_records: page.total_entries
37-
}
17+
tasks =
18+
Task
19+
|> project_filter(params)
20+
|> task_list_filter(params)
21+
|> task_type_filter(params)
22+
|> task_status_filter(params)
23+
|> sort_by_order
24+
|> Repo.all
3825

3926
conn
40-
|> render("index.json-api", data: page, opts: [meta: meta])
27+
|> render("index.json-api", data: tasks)
4128
end
4229

4330
def record(%Plug.Conn{params: %{"project_id" => _project_id} = params}, _number_as_id) do

0 commit comments

Comments
 (0)