2021-08-11 21:58:28 +00:00
|
|
|
defmodule Ketbin.Pastes.Paste do
|
|
|
|
use Ecto.Schema
|
|
|
|
import Ecto.Changeset
|
2022-05-06 18:34:59 +00:00
|
|
|
@derive {Jason.Encoder, only: [:content, :is_url, :belongs_to]}
|
2021-08-11 21:58:28 +00:00
|
|
|
|
2021-08-11 22:59:58 +00:00
|
|
|
@primary_key {:id, :string, autogenerate: false}
|
|
|
|
@derive {Phoenix.Param, key: :id}
|
2021-08-11 21:58:28 +00:00
|
|
|
schema "pastes" do
|
|
|
|
field :content, :string
|
|
|
|
field :is_url, :boolean, default: false
|
|
|
|
field :belongs_to, :id
|
2024-05-06 19:46:52 +00:00
|
|
|
|
|
|
|
timestamps()
|
2021-08-11 21:58:28 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
@doc false
|
|
|
|
def changeset(paste, attrs) do
|
|
|
|
paste
|
2021-08-14 21:49:03 +00:00
|
|
|
|> cast(attrs, [:is_url, :content, :id, :belongs_to])
|
2021-08-11 21:58:28 +00:00
|
|
|
|> validate_required([:is_url, :content])
|
2022-05-28 04:59:47 +00:00
|
|
|
|> unique_constraint(:id, name: :pastes_pkey)
|
2021-08-11 21:58:28 +00:00
|
|
|
end
|
|
|
|
end
|