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
30 lines (24 loc) · 784 Bytes
/
comment_controller.ex
File metadata and controls
30 lines (24 loc) · 784 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
30
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
def filter(_conn, query, "id", id_list) do
query |> id_filter(id_list)
end
def handle_create(conn, attributes) do
%Comment{}
|> Comment.create_changeset(attributes)
|> Repo.insert
|> CodeCorps.Analytics.Segment.track(:created, conn)
end
def handle_update(conn, comment, attributes) do
comment
|> Comment.changeset(attributes)
|> Repo.update
|> CodeCorps.Analytics.Segment.track(:edited, conn)
end
end