feat(chat): add messages
This commit is contained in:
22
lib/slax/chat/message.ex
Normal file
22
lib/slax/chat/message.ex
Normal file
@@ -0,0 +1,22 @@
|
||||
defmodule Slax.Chat.Message do
|
||||
use Ecto.Schema
|
||||
import Ecto.Changeset
|
||||
alias Slax.Chat.Room
|
||||
alias Slax.Accounts.User
|
||||
|
||||
schema "messages" do
|
||||
field :body, :string
|
||||
|
||||
belongs_to :user, User
|
||||
belongs_to :room, Room
|
||||
|
||||
timestamps(type: :utc_datetime)
|
||||
end
|
||||
|
||||
@doc false
|
||||
def changeset(message, attrs) do
|
||||
message
|
||||
|> cast(attrs, [:user_id, :room_id, :body])
|
||||
|> validate_required([:user_id, :room_id, :body])
|
||||
end
|
||||
end
|
@@ -1,11 +1,14 @@
|
||||
defmodule Slax.Chat.Room do
|
||||
use Ecto.Schema
|
||||
import Ecto.Changeset
|
||||
alias Slax.Chat.Message
|
||||
|
||||
schema "rooms" do
|
||||
field :name, :string
|
||||
field :topic, :string
|
||||
|
||||
has_many :messages, Message
|
||||
|
||||
timestamps(type: :utc_datetime)
|
||||
end
|
||||
|
||||
|
Reference in New Issue
Block a user