feat(chat): add messages

This commit is contained in:
2024-10-23 22:33:47 +00:00
parent b6a78ef403
commit ca90b77bcb
5 changed files with 80 additions and 1 deletions

22
lib/slax/chat/message.ex Normal file
View 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

View File

@@ -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