forked from code-corps/code-corps-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproject_controller.ex
More file actions
29 lines (22 loc) · 869 Bytes
/
project_controller.ex
File metadata and controls
29 lines (22 loc) · 869 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
defmodule CodeCorps.ProjectController do
use CodeCorps.Web, :controller
use JaResource
import CodeCorps.Helpers.Query, only: [slug_finder: 2]
alias CodeCorps.Project
plug :load_and_authorize_changeset, model: Project, only: [:create]
plug :load_and_authorize_resource, model: Project, only: [:update]
plug JaResource
def record(%Plug.Conn{params: %{"project_slug" => project_slug}}, nil) do
Project |> slug_finder(project_slug)
end
def record(%Plug.Conn{} = conn, id), do: super(conn, id)
def handle_index(_conn, %{"slug" => slug}) do
slugged_route = CodeCorps.SluggedRoute |> slug_finder(slug)
Project
|> Repo.all(organization_id: slugged_route.organization_id)
end
def handle_index(_conn, _params), do: Project
def handle_create(_conn, attributes) do
%Project{} |> Project.create_changeset(attributes)
end
end