remove clothes addition

This commit is contained in:
Lili (Tlapka) 2021-09-20 18:00:04 +02:00
parent cbb7ad3ce8
commit 2169e79b6f
3 changed files with 34 additions and 37 deletions

View File

@ -2,9 +2,8 @@ defmodule PokemonCoutureWeb.ClothesController do
use PokemonCoutureWeb, :controller use PokemonCoutureWeb, :controller
alias PokemonCouture.Shops alias PokemonCouture.Shops
alias PokemonCouture.Shops.Clothes
def create_shop_map(clothes, map) do def create_shop_map(clothes, map) do # helper function for index
case map[clothes.location] do case map[clothes.location] do
nil -> nil ->
Map.put(map, clothes.location, [clothes]) Map.put(map, clothes.location, [clothes])
@ -22,22 +21,22 @@ defmodule PokemonCoutureWeb.ClothesController do
render(conn, "index.html", clothes: clothes, clothes_map: clothes_map) render(conn, "index.html", clothes: clothes, clothes_map: clothes_map)
end end
def new(conn, _params) do # def new(conn, _params) do
changeset = Shops.change_clothes(%Clothes{}) # changeset = Shops.change_clothes(%Clothes{})
render(conn, "new.html", changeset: changeset) # render(conn, "new.html", changeset: changeset)
end # end
def create(conn, %{"clothes" => clothes_params}) do # def create(conn, %{"clothes" => clothes_params}) do
case Shops.create_clothes(clothes_params) do # case Shops.create_clothes(clothes_params) do
{:ok, clothes} -> # {:ok, clothes} ->
conn # conn
|> put_flash(:info, "Clothes created successfully.") # |> put_flash(:info, "Clothes created successfully.")
|> redirect(to: Routes.clothes_path(conn, :show, clothes)) # |> redirect(to: Routes.clothes_path(conn, :show, clothes))
{:error, %Ecto.Changeset{} = changeset} -> # {:error, %Ecto.Changeset{} = changeset} ->
render(conn, "new.html", changeset: changeset) # render(conn, "new.html", changeset: changeset)
end # end
end # end
def show(conn, %{"id" => id}) do def show(conn, %{"id" => id}) do
clothes = Shops.get_clothes!(id) clothes = Shops.get_clothes!(id)

View File

@ -27,5 +27,3 @@
</tbody> </tbody>
</table> </table>
<% end %> <% end %>
<span><%= link "New Clothes", to: Routes.clothes_path(@conn, :new) %></span>

View File

@ -19,29 +19,29 @@ defmodule PokemonCoutureWeb.ClothesControllerTest do
end end
end end
describe "new clothes" do # describe "new clothes" do
test "renders form", %{conn: conn} do # test "renders form", %{conn: conn} do
conn = get(conn, Routes.clothes_path(conn, :new)) # conn = get(conn, Routes.clothes_path(conn, :new))
assert html_response(conn, 200) =~ "New Clothes" # assert html_response(conn, 200) =~ "New Clothes"
end # end
end # end
describe "create clothes" do # describe "create clothes" do
test "redirects to show when data is valid", %{conn: conn} do # test "redirects to show when data is valid", %{conn: conn} do
conn = post(conn, Routes.clothes_path(conn, :create), clothes: @create_attrs) # conn = post(conn, Routes.clothes_path(conn, :create), clothes: @create_attrs)
assert %{id: id} = redirected_params(conn) # assert %{id: id} = redirected_params(conn)
assert redirected_to(conn) == Routes.clothes_path(conn, :show, id) # assert redirected_to(conn) == Routes.clothes_path(conn, :show, id)
conn = get(conn, Routes.clothes_path(conn, :show, id)) # conn = get(conn, Routes.clothes_path(conn, :show, id))
assert html_response(conn, 200) =~ "Show Clothes" # assert html_response(conn, 200) =~ "Show Clothes"
end # end
test "renders errors when data is invalid", %{conn: conn} do # test "renders errors when data is invalid", %{conn: conn} do
conn = post(conn, Routes.clothes_path(conn, :create), clothes: @invalid_attrs) # conn = post(conn, Routes.clothes_path(conn, :create), clothes: @invalid_attrs)
assert html_response(conn, 200) =~ "New Clothes" # assert html_response(conn, 200) =~ "New Clothes"
end # end
end # end
describe "edit clothes" do describe "edit clothes" do
setup [:create_clothes] setup [:create_clothes]