don't allow empty group titles

This commit is contained in:
Shadowfacts 2019-08-31 15:13:29 -04:00
parent 9c1bbbbf23
commit 0ced9df13a
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
1 changed files with 13 additions and 6 deletions

View File

@ -54,15 +54,22 @@ defmodule FrenzyWeb.GroupController do
def create(conn, %{"group" => %{"title" => title}}) do
user = conn.assigns[:user]
title = title |> String.trim()
changeset =
Ecto.build_assoc(user, :groups, %{
title: title
})
if String.length(title) > 0 do
changeset =
Ecto.build_assoc(user, :groups, %{
title: title
})
{:ok, group} = Repo.insert(changeset)
{:ok, group} = Repo.insert(changeset)
redirect(conn, to: Routes.group_path(Endpoint, :show, group.id))
redirect(conn, to: Routes.group_path(Endpoint, :show, group.id))
else
conn
|> put_flash(:error, "Group title must not be empty")
|> redirect(to: Routes.group_path(Endpoint, :new))
end
end
def delete(conn, _params) do