debianize-mobilizon/lib/mobilizon/actors/follower.ex
Thomas Citharel c1e6612405
[WIP] Test transmogrifier
Introduce MobilizonWeb.API namespace

Signed-off-by: Thomas Citharel <tcit@tcit.fr>

Format

Signed-off-by: Thomas Citharel <tcit@tcit.fr>

WIP

Signed-off-by: Thomas Citharel <tcit@tcit.fr>

remove unneeded code

Signed-off-by: Thomas Citharel <tcit@tcit.fr>

Fix tests

Signed-off-by: Thomas Citharel <tcit@tcit.fr>

Fix warnings

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
2018-12-20 17:44:33 +01:00

29 lines
831 B
Elixir

defmodule Mobilizon.Actors.Follower do
@moduledoc """
Represents the following of an actor to another actor
"""
use Ecto.Schema
import Ecto.Changeset
alias Mobilizon.Actors.Follower
alias Mobilizon.Actors.Actor
schema "followers" do
field(:approved, :boolean, default: false)
field(:score, :integer, default: 1000)
belongs_to(:target_actor, Actor)
belongs_to(:actor, Actor)
end
@doc false
def changeset(%Follower{} = member, attrs) do
member
|> cast(attrs, [:score, :approved, :target_actor_id, :actor_id])
|> validate_required([:score, :approved, :target_actor_id, :actor_id])
|> unique_constraint(:target_actor_id, name: :followers_actor_target_actor_unique_index)
end
def url(%Follower{id: id}) do
"#{MobilizonWeb.Endpoint.url()}/follow/#{id}/activity"
end
end