add shops context, clothes and users-clothes
users-clothes is a many-to-many unique relationship
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
defmodule PokemonCoutureWeb.ClothesController do
|
||||
use PokemonCoutureWeb, :controller
|
||||
|
||||
alias PokemonCouture.Shops
|
||||
alias PokemonCouture.Shops.Clothes
|
||||
|
||||
def index(conn, _params) do
|
||||
clothes = Shops.list_clothes()
|
||||
render(conn, "index.html", clothes: clothes)
|
||||
end
|
||||
|
||||
def new(conn, _params) do
|
||||
changeset = Shops.change_clothes(%Clothes{})
|
||||
render(conn, "new.html", changeset: changeset)
|
||||
end
|
||||
|
||||
def create(conn, %{"clothes" => clothes_params}) do
|
||||
case Shops.create_clothes(clothes_params) do
|
||||
{:ok, clothes} ->
|
||||
conn
|
||||
|> put_flash(:info, "Clothes created successfully.")
|
||||
|> redirect(to: Routes.clothes_path(conn, :show, clothes))
|
||||
|
||||
{:error, %Ecto.Changeset{} = changeset} ->
|
||||
render(conn, "new.html", changeset: changeset)
|
||||
end
|
||||
end
|
||||
|
||||
def show(conn, %{"id" => id}) do
|
||||
clothes = Shops.get_clothes!(id)
|
||||
render(conn, "show.html", clothes: clothes)
|
||||
end
|
||||
|
||||
def edit(conn, %{"id" => id}) do
|
||||
clothes = Shops.get_clothes!(id)
|
||||
changeset = Shops.change_clothes(clothes)
|
||||
render(conn, "edit.html", clothes: clothes, changeset: changeset)
|
||||
end
|
||||
|
||||
def update(conn, %{"id" => id, "clothes" => clothes_params}) do
|
||||
clothes = Shops.get_clothes!(id)
|
||||
|
||||
case Shops.update_clothes(clothes, clothes_params) do
|
||||
{:ok, clothes} ->
|
||||
conn
|
||||
|> put_flash(:info, "Clothes updated successfully.")
|
||||
|> redirect(to: Routes.clothes_path(conn, :show, clothes))
|
||||
|
||||
{:error, %Ecto.Changeset{} = changeset} ->
|
||||
render(conn, "edit.html", clothes: clothes, changeset: changeset)
|
||||
end
|
||||
end
|
||||
|
||||
def delete(conn, %{"id" => id}) do
|
||||
clothes = Shops.get_clothes!(id)
|
||||
{:ok, _clothes} = Shops.delete_clothes(clothes)
|
||||
|
||||
conn
|
||||
|> put_flash(:info, "Clothes deleted successfully.")
|
||||
|> redirect(to: Routes.clothes_path(conn, :index))
|
||||
end
|
||||
end
|
||||
@@ -20,6 +20,7 @@ defmodule PokemonCoutureWeb.Router do
|
||||
pipe_through :browser
|
||||
|
||||
get "/", PageController, :index
|
||||
resources "/clothes", ClothesController
|
||||
end
|
||||
|
||||
# Other scopes may use custom stacks.
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
<h1>Edit Clothes</h1>
|
||||
|
||||
<%= render "form.html", Map.put(assigns, :action, Routes.clothes_path(@conn, :update, @clothes)) %>
|
||||
|
||||
<span><%= link "Back", to: Routes.clothes_path(@conn, :index) %></span>
|
||||
@@ -0,0 +1,23 @@
|
||||
<%= form_for @changeset, @action, fn f -> %>
|
||||
<%= if @changeset.action do %>
|
||||
<div class="alert alert-danger">
|
||||
<p>Oops, something went wrong! Please check the errors below.</p>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<%= label f, :name %>
|
||||
<%= text_input f, :name %>
|
||||
<%= error_tag f, :name %>
|
||||
|
||||
<%= label f, :location %>
|
||||
<%= text_input f, :location %>
|
||||
<%= error_tag f, :location %>
|
||||
|
||||
<%= label f, :game %>
|
||||
<%= text_input f, :game %>
|
||||
<%= error_tag f, :game %>
|
||||
|
||||
<div>
|
||||
<%= submit "Save" %>
|
||||
</div>
|
||||
<% end %>
|
||||
@@ -0,0 +1,30 @@
|
||||
<h1>Listing Clothes</h1>
|
||||
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Location</th>
|
||||
<th>Game</th>
|
||||
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<%= for clothes <- @clothes do %>
|
||||
<tr>
|
||||
<td><%= clothes.name %></td>
|
||||
<td><%= clothes.location %></td>
|
||||
<td><%= clothes.game %></td>
|
||||
|
||||
<td>
|
||||
<span><%= link "Show", to: Routes.clothes_path(@conn, :show, clothes) %></span>
|
||||
<span><%= link "Edit", to: Routes.clothes_path(@conn, :edit, clothes) %></span>
|
||||
<span><%= link "Delete", to: Routes.clothes_path(@conn, :delete, clothes), method: :delete, data: [confirm: "Are you sure?"] %></span>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<span><%= link "New Clothes", to: Routes.clothes_path(@conn, :new) %></span>
|
||||
@@ -0,0 +1,5 @@
|
||||
<h1>New Clothes</h1>
|
||||
|
||||
<%= render "form.html", Map.put(assigns, :action, Routes.clothes_path(@conn, :create)) %>
|
||||
|
||||
<span><%= link "Back", to: Routes.clothes_path(@conn, :index) %></span>
|
||||
@@ -0,0 +1,23 @@
|
||||
<h1>Show Clothes</h1>
|
||||
|
||||
<ul>
|
||||
|
||||
<li>
|
||||
<strong>Name:</strong>
|
||||
<%= @clothes.name %>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<strong>Location:</strong>
|
||||
<%= @clothes.location %>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<strong>Game:</strong>
|
||||
<%= @clothes.game %>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
||||
<span><%= link "Edit", to: Routes.clothes_path(@conn, :edit, @clothes) %></span>
|
||||
<span><%= link "Back", to: Routes.clothes_path(@conn, :index) %></span>
|
||||
@@ -0,0 +1,3 @@
|
||||
defmodule PokemonCoutureWeb.ClothesView do
|
||||
use PokemonCoutureWeb, :view
|
||||
end
|
||||
Reference in New Issue
Block a user