Current section
Files
Jump to
Current section
Files
lib/ex_dav/storage/postgres/schemas/resource.ex
defmodule ExDav.Storage.Postgres.Schemas.Resource do
@moduledoc "A single DAV resource (a calendar object or vCard)."
use Ecto.Schema
import Ecto.Changeset
alias ExDav.Storage.Postgres.Schemas.Collection
schema "dav_resources" do
field :name, :string
field :uid, :string
field :component, :string
field :body, :string
field :content_type, :string
field :etag, :string
field :version, :integer, default: 0
belongs_to :collection, Collection
timestamps(type: :utc_datetime)
end
def changeset(resource, attrs) do
resource
|> cast(attrs, [:name, :uid, :component, :body, :content_type, :etag, :version, :collection_id])
|> validate_required([:name, :body, :etag, :collection_id])
|> unique_constraint([:collection_id, :name])
end
end