mobilizon.chapril.org-mobil.../lib/mobilizon/events/feed_token.ex

41 lines
875 B
Elixir
Raw Normal View History

defmodule Mobilizon.Events.FeedToken do
@moduledoc """
2019-09-13 01:01:17 +02:00
Represents a token for a feed of events.
"""
2019-09-13 01:01:17 +02:00
use Ecto.Schema
2019-09-13 01:01:17 +02:00
import Ecto.Changeset
2019-09-13 01:01:17 +02:00
alias Mobilizon.Actors.Actor
alias Mobilizon.Users.User
2019-09-13 01:01:17 +02:00
@type t :: %__MODULE__{
token: Ecto.UUID.t(),
actor: Actor.t() | nil,
2019-09-13 01:01:17 +02:00
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)
2019-09-13 01:01:17 +02:00
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()
2019-09-13 01:55:45 +02:00
def changeset(%__MODULE__{} = feed_token, attrs) do
feed_token
2019-09-13 01:01:17 +02:00
|> cast(attrs, @attrs)
|> validate_required(@required_attrs)
end
end