2022-04-15 15:00:42 -04:00
|
|
|
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
|
2022-04-20 18:03:17 -04:00
|
|
|
|
|
|
|
def serialize(c) do
|
2022-04-20 19:23:27 -04:00
|
|
|
%{"body" => c.comment, "user" => c.user.username, "user_id" => c.user_id, "id" => c.id, "inserted_at" => c.inserted_at}
|
2022-04-20 18:03:17 -04:00
|
|
|
end
|
2022-04-15 15:00:42 -04:00
|
|
|
end
|