mobilizon.chapril.org-mobil.../lib/mobilizon/events/feed_token.ex
Thomas Citharel 1893d9f55b
Various refactoring and typespec improvements
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
2021-09-26 17:52:24 +02:00

41 lines
875 B
Elixir

defmodule Mobilizon.Events.FeedToken do
@moduledoc """
Represents a token for a feed of events.
"""
use Ecto.Schema
import Ecto.Changeset
alias Mobilizon.Actors.Actor
alias Mobilizon.Users.User
@type t :: %__MODULE__{
token: Ecto.UUID.t(),
actor: Actor.t() | nil,
user: User.t()
}
@required_attrs [:token, :user_id]
@optional_attrs [:actor_id]
@attrs @required_attrs ++ @optional_attrs
@primary_key false
schema "feed_tokens" do
field(:token, Ecto.UUID, primary_key: true)
belongs_to(:actor, Actor)
belongs_to(:user, User)
timestamps(updated_at: false)
end
@doc false
@spec changeset(t | Ecto.Schema.t(), map) :: Ecto.Changeset.t()
def changeset(%__MODULE__{} = feed_token, attrs) do
feed_token
|> cast(attrs, @attrs)
|> validate_required(@required_attrs)
end
end