Add actor.ex
This commit is contained in:
parent
62dbe3ef24
commit
b596606c14
1 changed files with 109 additions and 0 deletions
109
lib/nulla/models/actor.ex
Normal file
109
lib/nulla/models/actor.ex
Normal file
|
@ -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
|
Loading…
Add table
Add a link
Reference in a new issue