diff --git a/lib/nulla/models/actor.ex b/lib/nulla/models/actor.ex new file mode 100644 index 0000000..653c37f --- /dev/null +++ b/lib/nulla/models/actor.ex @@ -0,0 +1,109 @@ +defmodule Nulla.Models.Actor do + use Ecto.Schema + import Ecto.Changeset + import Ecto.Query + alias Nulla.Repo + alias Nulla.Snowflake + alias Nulla.Models.User + alias Nulla.Models.Note + + @primary_key {:id, :integer, autogenerate: false} + schema "actors" do + field :type, :string + field :following, :string + field :followers, :string + field :inbox, :string + field :outbox, :string + field :featured, :string + field :featuredTags, :string + field :preferredUsername, :string + field :name, :string + field :summary, :string + field :url, :string + field :manuallyApprovesFollowers, :boolean + field :discoverable, :boolean, default: true + field :indexable, :boolean, default: true + field :published, :utc_datetime + field :memorial, :boolean, default: false + field :publicKey, {:array, :map} + field :tag, {:array, :map} + field :attachment, {:array, :map} + field :endpoints, :map + field :icon, :map + field :image, :map + field :vcard_bday, :date + field :vcard_Address, :string + + has_one :user, User + has_many :notes, Note + has_many :media_attachments, through: [:notes, :media_attachments] + end + + @doc false + def changeset(actor, attrs) do + actor + |> cast(attrs, [ + :id, + :type, + :following, + :followers, + :inbox, + :outbox, + :featured, + :featuredTags, + :preferredUsername, + :name, + :summary, + :url, + :manuallyApprovesFollowers, + :discoverable, + :indexable, + :published, + :memorial, + :publicKey, + :tag, + :attachment, + :endpoints, + :icon, + :image, + :vcard_bday, + :vcard_Address + ]) + |> validate_required([ + :id, + :type, + :following, + :followers, + :inbox, + :outbox, + :featured, + :featuredTags, + :preferredUsername, + :name, + :summary, + :url, + :manuallyApprovesFollowers, + :discoverable, + :indexable, + :published, + :memorial, + :publicKey, + :tag, + :attachment, + :endpoints, + :icon, + :image, + :vcard_bday, + :vcard_Address + ]) + end + + def create_user(attrs) when is_map(attrs) do + id = Snowflake.next_id() + + %__MODULE__{} + |> changeset(attrs) + |> Ecto.Changeset.put_change(:id, id) + |> Repo.insert() + end +end