Current section

Files

Jump to
nldoc_spec_event lib nldoc spec event done.ex
Raw

lib/nldoc/spec/event/done.ex

defmodule NLdoc.Spec.Event.Done do
@moduledoc """
This module defines the Ecto schema for the NLdoc Event 'Done'.
"""
use NLdoc.SpecDef.Schema, type: "https://event.spec.nldoc.nl/done"
defmodule Context do
@moduledoc false
use NLdoc.SpecDef.Schema, type: nil
typed_embedded_schema null: false do
field :content_type, :string
field :location, :string
end
def changeset(object, attrs) do
fields = [:content_type, :location]
object
|> cast(attrs, fields, @cast_opts)
|> validate_required(fields)
end
end
typed_embedded_schema null: false do
field :type, :string, default: @resource_type
field :timestamp, :utc_datetime
field :trace_id, :string
embeds_one :context, Context
end
def changeset(object, attrs) do
fields = [:type, :timestamp, :trace_id]
object
|> cast(attrs, fields, @cast_opts)
|> cast_embed(:context)
|> validate_required([:context] ++ fields)
|> validate_inclusion(:type, [@resource_type])
end
end