2022-04-06 14:13:54 -04:00
|
|
|
defmodule Aggiedit.Rooms.Room do
|
|
|
|
use Ecto.Schema
|
|
|
|
import Ecto.Changeset
|
|
|
|
|
|
|
|
schema "rooms" do
|
|
|
|
field :domain, :string
|
|
|
|
|
|
|
|
has_many :users, Aggiedit.Accounts.User
|
2022-04-06 16:16:29 -04:00
|
|
|
has_many :posts, Aggiedit.Rooms.Post
|
2022-04-06 14:13:54 -04:00
|
|
|
|
|
|
|
timestamps()
|
|
|
|
end
|
|
|
|
|
|
|
|
@doc false
|
|
|
|
def changeset(room, attrs) do
|
|
|
|
room
|
|
|
|
|> cast(attrs, [:domain])
|
|
|
|
|> validate_required([:domain])
|
|
|
|
|> validate_length(:domain, max: 160)
|
|
|
|
|> validate_format(:domain, ~r/^[^\s\.]+\.[^\.\s]+$/, message: "Domain cannot be a subdomain, and cannot have spaces")
|
|
|
|
|> unique_constraint(:domain)
|
|
|
|
end
|
|
|
|
end
|