2017-12-08 09:58:14 +01:00
|
|
|
defmodule Eventos.Accounts.Account do
|
|
|
|
use Ecto.Schema
|
|
|
|
import Ecto.Changeset
|
|
|
|
alias Eventos.Accounts.{Account, GroupAccount, GroupRequest, Group, User}
|
|
|
|
alias Eventos.Events.Event
|
|
|
|
|
|
|
|
schema "accounts" do
|
2018-01-09 17:52:26 +01:00
|
|
|
field :username, :string
|
2017-12-08 09:58:14 +01:00
|
|
|
field :description, :string
|
|
|
|
field :display_name, :string
|
2018-01-09 17:52:26 +01:00
|
|
|
field :domain, :string, default: nil
|
2017-12-08 09:58:14 +01:00
|
|
|
field :private_key, :string
|
|
|
|
field :public_key, :string
|
|
|
|
field :suspended, :boolean, default: false
|
|
|
|
field :uri, :string
|
|
|
|
field :url, :string
|
|
|
|
has_many :organized_events, Event
|
|
|
|
many_to_many :groups, Group, join_through: GroupAccount
|
|
|
|
has_many :group_request, GroupRequest
|
2018-01-09 17:52:26 +01:00
|
|
|
has_one :user, User
|
2017-12-08 09:58:14 +01:00
|
|
|
|
|
|
|
timestamps()
|
|
|
|
end
|
|
|
|
|
|
|
|
@doc false
|
|
|
|
def changeset(%Account{} = account, attrs) do
|
|
|
|
account
|
|
|
|
|> cast(attrs, [:username, :domain, :display_name, :description, :private_key, :public_key, :suspended, :uri, :url])
|
2018-01-09 17:52:26 +01:00
|
|
|
|> validate_required([:username, :display_name, :description, :private_key, :public_key, :suspended])
|
|
|
|
|> unique_constraint(:username, name: :accounts_username_domain_index)
|
2017-12-08 09:58:14 +01:00
|
|
|
end
|
|
|
|
end
|