fix conversation controller

This commit is contained in:
byte[] 2019-12-04 08:27:35 -05:00
parent 3f6322ca81
commit 50759774f6
2 changed files with 2 additions and 5 deletions

View file

@ -48,6 +48,7 @@ defmodule Philomena.Conversations.Conversation do
|> set_slug()
|> set_last_message()
|> cast_assoc(:messages, with: {Message, :creation_changeset, [from]})
|> validate_length(:messages, is: 1)
end
defp set_slug(changeset) do

View file

@ -62,11 +62,7 @@ defmodule PhilomenaWeb.ConversationController do
render(conn, "new.html", changeset: changeset)
end
# Somewhat annoying, cast_assoc has no "limit" validation so we force it
# here to require exactly 1
def create(conn, %{"conversation" => %{"messages" => %{"0" => message_params} = messages_params} = conversation_params})
when %{"0" => message_params} == messages_params
do
def create(conn, %{"conversation" => conversation_params}) do
user = conn.assigns.current_user
case Conversations.create_conversation(user, conversation_params) do