-
Notifications
You must be signed in to change notification settings - Fork 83
Expand file tree
/
Copy pathgithub_comment.ex
More file actions
54 lines (46 loc) · 1.62 KB
/
github_comment.ex
File metadata and controls
54 lines (46 loc) · 1.62 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
defmodule CodeCorps.GithubComment do
use Ecto.Schema
alias Ecto.Changeset
@type t :: %__MODULE__{}
schema "github_comments" do
field :body, :string
field :github_created_at, :utc_datetime
field :github_id, :integer
field :github_updated_at, :utc_datetime
field :html_url, :string
field :url, :string
belongs_to :github_issue, CodeCorps.GithubIssue
belongs_to :github_repo, CodeCorps.GithubRepo
belongs_to :github_user, CodeCorps.GithubUser
timestamps()
end
@doc false
defp changeset(struct, params) do
struct
|> Changeset.cast(params, [:body, :github_created_at, :github_id, :github_updated_at, :html_url, :url])
|> Changeset.validate_required([:body, :github_created_at, :github_id, :github_updated_at, :html_url, :url])
|> Changeset.unique_constraint(:github_id)
end
@doc ~S"""
Default changeset used to create a `CodeCorps.GithubComment` record.
"""
def create_changeset(struct, params) do
struct
|> changeset(params)
|> Changeset.cast(params, [:github_issue_id, :github_repo_id, :github_user_id])
|> Changeset.assoc_constraint(:github_issue)
|> Changeset.assoc_constraint(:github_repo)
|> Changeset.assoc_constraint(:github_user)
end
@doc ~S"""
Default changeset used to update a `CodeCorps.GithubComment` record.
"""
def update_changeset(struct, params) do
struct
|> changeset(params)
|> Changeset.cast(params, [:github_issue_id, :github_repo_id, :github_user_id])
|> Changeset.assoc_constraint(:github_issue)
|> Changeset.assoc_constraint(:github_repo)
|> Changeset.assoc_constraint(:github_user)
end
end