summaryrefslogtreecommitdiff
path: root/lib/aggiedit/rooms/comment.ex
blob: 01f411a9eb657fd729679f65ba1edf8cef66572f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
defmodule Aggiedit.Post.Comment do
  use Ecto.Schema
  import Ecto.Changeset

  schema "post_comments" do
    field :comment, :string

    belongs_to :user, Aggiedit.Accounts.User
    belongs_to :post, Aggiedit.Rooms.Post

    timestamps()
  end

  @doc false
  def changeset(comment, attrs) do
    comment
    |> cast(attrs, [:comment])
    |> validate_required([:comment])
  end

  def serialize(c) do
    %{"body" => c.comment, "user" => c.user.username, "id" => c.id, "inserted_at" => c.inserted_at}
  end
end