Preparatory work
This commit is contained in:
parent
a22ba724df
commit
386a331956
9 changed files with 217 additions and 1 deletions
20
lib/birdy_chat_web/api/messages/controller.ex
Normal file
20
lib/birdy_chat_web/api/messages/controller.ex
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
defmodule BirdyChatWeb.Api.Messages.Controller do
|
||||
use BirdyChatWeb, :controller
|
||||
|
||||
def create(conn, params) do
|
||||
case BirdyChat.Message.validate(params) do
|
||||
{:ok, changeset} ->
|
||||
case BirdyChat.Message.write(changeset.changes) do
|
||||
{:ok, msg} ->
|
||||
conn
|
||||
|> put_status(:created)
|
||||
|> render(:create, message: msg)
|
||||
end
|
||||
|
||||
{:error, changeset} ->
|
||||
conn
|
||||
|> put_status(:unprocessable_entity)
|
||||
|> render(:error, changeset: changeset)
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue