|
1 | 1 | defmodule CodeCorpsWeb.GithubRepoController do |
2 | 2 | use CodeCorpsWeb, :controller |
3 | | - use JaResource |
4 | 3 |
|
5 | | - import CodeCorps.Helpers.Query, only: [id_filter: 2] |
| 4 | + alias CodeCorps.{GithubRepo, Helpers.Query} |
6 | 5 |
|
7 | | - alias CodeCorps.{GithubRepo} |
| 6 | + action_fallback CodeCorpsWeb.FallbackController |
| 7 | + plug CodeCorpsWeb.Plug.DataToAttributes |
| 8 | + plug CodeCorpsWeb.Plug.IdsToIntegers |
8 | 9 |
|
9 | | - @preloads [:github_app_installation] |
10 | | - |
11 | | - plug :load_resource, model: GithubRepo, only: [:show], preload: @preloads |
12 | | - |
13 | | - plug JaResource |
14 | | - |
15 | | - @spec model :: module |
16 | | - def model, do: CodeCorps.GithubRepo |
| 10 | + @spec index(Conn.t, map) :: Conn.t |
| 11 | + def index(%Conn{} = conn, %{} = params) do |
| 12 | + with github_repos <- GithubRepo |> Query.id_filter(params) |> Repo.all do |
| 13 | + conn |> render("index.json-api", data: github_repos) |
| 14 | + end |
| 15 | + end |
17 | 16 |
|
18 | | - @spec filter(Plug.Conn.t, Ecto.Query.t, String.t, String.t) :: Ecto.Query.t |
19 | | - def filter(_conn, query, "id", id_list) do |
20 | | - query |> id_filter(id_list) |
| 17 | + @spec show(Conn.t, map) :: Conn.t |
| 18 | + def show(%Conn{} = conn, %{"id" => id}) do |
| 19 | + with %GithubRepo{} = github_repo <- GithubRepo |> Repo.get(id) do |
| 20 | + conn |> render("show.json-api", data: github_repo) |
| 21 | + end |
21 | 22 | end |
22 | 23 | end |
0 commit comments