forked from code-corps/code-corps-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomment_controller.ex
More file actions
27 lines (21 loc) · 836 Bytes
/
comment_controller.ex
File metadata and controls
27 lines (21 loc) · 836 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
defmodule CodeCorps.CommentController do
use CodeCorps.Web, :controller
use JaResource
import CodeCorps.Helpers.Query, only: [id_filter: 2]
alias CodeCorps.Comment
plug :load_and_authorize_changeset, model: Comment, only: [:create]
plug :load_and_authorize_resource, model: Comment, only: [:update]
plug JaResource
@spec filter(Plug.Conn.t, Ecto.Query.t, String.t, String.t) :: Ecto.Query.t
def filter(_conn, query, "id", id_list) do
query |> id_filter(id_list)
end
@spec handle_create(Plug.Conn.t, map) :: Ecto.Changeset.t
def handle_create(_conn, attributes) do
%Comment{} |> Comment.create_changeset(attributes)
end
@spec handle_update(Plug.Conn.t, Comment.t, map) :: Ecto.Changeset.t
def handle_update(_conn, comment, attributes) do
comment |> Comment.changeset(attributes)
end
end