katbin/lib/ketbin/pastes/paste.ex
Amogh Lele 20a0b45954
feat(pastes): add REST routes to view and create pastes
Signed-off-by: Amogh Lele <amogh@dyte.io>
2022-05-07 00:04:59 +05:30

21 lines
526 B
Elixir

defmodule Ketbin.Pastes.Paste do
use Ecto.Schema
import Ecto.Changeset
@derive {Jason.Encoder, only: [:content, :is_url, :belongs_to]}
@primary_key {:id, :string, autogenerate: false}
@derive {Phoenix.Param, key: :id}
schema "pastes" do
field :content, :string
field :is_url, :boolean, default: false
field :belongs_to, :id
end
@doc false
def changeset(paste, attrs) do
paste
|> cast(attrs, [:is_url, :content, :id, :belongs_to])
|> validate_required([:is_url, :content])
end
end