forked from code-corps/code-corps-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomment.ex
More file actions
38 lines (32 loc) · 892 Bytes
/
comment.ex
File metadata and controls
38 lines (32 loc) · 892 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
31
32
33
34
35
36
37
38
defmodule CodeCorps.Comment do
use CodeCorps.Web, :model
import CodeCorps.ModelHelpers
alias CodeCorps.MarkdownRenderer
schema "comments" do
field :body, :string
field :markdown, :string
belongs_to :user, CodeCorps.User
belongs_to :task, CodeCorps.Task
timestamps()
end
@doc """
Builds a changeset based on the `struct` and `params`.
"""
def changeset(struct, params \\ %{}) do
struct
|> cast(params, [:markdown])
|> validate_required([:markdown])
|> MarkdownRenderer.render_markdown_to_html(:markdown, :body)
end
def create_changeset(struct, params) do
struct
|> changeset(params)
|> cast(params, [:task_id, :user_id])
|> validate_required([:task_id, :user_id])
|> assoc_constraint(:task)
|> assoc_constraint(:user)
end
def index_filters(query, params) do
query |> task_filter(params)
end
end