2019-03-08 12:25:06 +01:00
|
|
|
defmodule Mobilizon.Events.FeedToken do
|
|
|
|
@moduledoc """
|
2019-09-13 01:01:17 +02:00
|
|
|
Represents a token for a feed of events.
|
2019-03-08 12:25:06 +01:00
|
|
|
"""
|
2019-09-13 01:01:17 +02:00
|
|
|
|
2019-03-08 12:25:06 +01:00
|
|
|
use Ecto.Schema
|
2019-09-13 01:01:17 +02:00
|
|
|
|
2019-03-08 12:25:06 +01:00
|
|
|
import Ecto.Changeset
|
2019-09-13 01:01:17 +02:00
|
|
|
|
2019-03-08 12:25:06 +01:00
|
|
|
alias Mobilizon.Actors.Actor
|
|
|
|
alias Mobilizon.Users.User
|
|
|
|
|
2019-09-13 01:01:17 +02:00
|
|
|
@type t :: %__MODULE__{
|
|
|
|
token: Ecto.UUID.t(),
|
2021-09-24 16:46:42 +02:00
|
|
|
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
|
|
|
|
|
2019-03-08 12:25:06 +01:00
|
|
|
@primary_key false
|
2019-03-08 18:52:27 +01:00
|
|
|
schema "feed_tokens" do
|
|
|
|
field(:token, Ecto.UUID, primary_key: true)
|
2019-09-13 01:01:17 +02:00
|
|
|
|
2019-03-08 12:25:06 +01:00
|
|
|
belongs_to(:actor, Actor)
|
|
|
|
belongs_to(:user, User)
|
|
|
|
|
|
|
|
timestamps(updated_at: false)
|
|
|
|
end
|
|
|
|
|
|
|
|
@doc false
|
2021-09-24 16:46:42 +02:00
|
|
|
@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
|
2019-03-08 12:25:06 +01:00
|
|
|
feed_token
|
2019-09-13 01:01:17 +02:00
|
|
|
|> cast(attrs, @attrs)
|
|
|
|
|> validate_required(@required_attrs)
|
2019-03-08 12:25:06 +01:00
|
|
|
end
|
|
|
|
end
|