AUTOGEN: Performances.
This commit is contained in:
104
lib/runosaari/schedule.ex
Normal file
104
lib/runosaari/schedule.ex
Normal file
@@ -0,0 +1,104 @@
|
||||
defmodule Runosaari.Schedule do
|
||||
@moduledoc """
|
||||
The Schedule context.
|
||||
"""
|
||||
|
||||
import Ecto.Query, warn: false
|
||||
alias Runosaari.Repo
|
||||
|
||||
alias Runosaari.Schedule.Performance
|
||||
|
||||
@doc """
|
||||
Returns the list of performances.
|
||||
|
||||
## Examples
|
||||
|
||||
iex> list_performances()
|
||||
[%Performance{}, ...]
|
||||
|
||||
"""
|
||||
def list_performances do
|
||||
Repo.all(Performance)
|
||||
end
|
||||
|
||||
@doc """
|
||||
Gets a single performance.
|
||||
|
||||
Raises `Ecto.NoResultsError` if the Performance does not exist.
|
||||
|
||||
## Examples
|
||||
|
||||
iex> get_performance!(123)
|
||||
%Performance{}
|
||||
|
||||
iex> get_performance!(456)
|
||||
** (Ecto.NoResultsError)
|
||||
|
||||
"""
|
||||
def get_performance!(id), do: Repo.get!(Performance, id)
|
||||
|
||||
@doc """
|
||||
Creates a performance.
|
||||
|
||||
## Examples
|
||||
|
||||
iex> create_performance(%{field: value})
|
||||
{:ok, %Performance{}}
|
||||
|
||||
iex> create_performance(%{field: bad_value})
|
||||
{:error, %Ecto.Changeset{}}
|
||||
|
||||
"""
|
||||
def create_performance(attrs \\ %{}) do
|
||||
%Performance{}
|
||||
|> Performance.changeset(attrs)
|
||||
|> Repo.insert()
|
||||
end
|
||||
|
||||
@doc """
|
||||
Updates a performance.
|
||||
|
||||
## Examples
|
||||
|
||||
iex> update_performance(performance, %{field: new_value})
|
||||
{:ok, %Performance{}}
|
||||
|
||||
iex> update_performance(performance, %{field: bad_value})
|
||||
{:error, %Ecto.Changeset{}}
|
||||
|
||||
"""
|
||||
def update_performance(%Performance{} = performance, attrs) do
|
||||
performance
|
||||
|> Performance.changeset(attrs)
|
||||
|> Repo.update()
|
||||
end
|
||||
|
||||
@doc """
|
||||
Deletes a performance.
|
||||
|
||||
## Examples
|
||||
|
||||
iex> delete_performance(performance)
|
||||
{:ok, %Performance{}}
|
||||
|
||||
iex> delete_performance(performance)
|
||||
{:error, %Ecto.Changeset{}}
|
||||
|
||||
"""
|
||||
def delete_performance(%Performance{} = performance) do
|
||||
Repo.delete(performance)
|
||||
end
|
||||
|
||||
@doc """
|
||||
Returns an `%Ecto.Changeset{}` for tracking performance changes.
|
||||
|
||||
## Examples
|
||||
|
||||
iex> change_performance(performance)
|
||||
%Ecto.Changeset{data: %Performance{}}
|
||||
|
||||
"""
|
||||
def change_performance(%Performance{} = performance, attrs \\ %{}) do
|
||||
Performance.changeset(performance, attrs)
|
||||
end
|
||||
end
|
||||
21
lib/runosaari/schedule/performance.ex
Normal file
21
lib/runosaari/schedule/performance.ex
Normal file
@@ -0,0 +1,21 @@
|
||||
defmodule Runosaari.Schedule.Performance do
|
||||
use Ecto.Schema
|
||||
import Ecto.Changeset
|
||||
|
||||
schema "performances" do
|
||||
field :description, :string
|
||||
field :notes, :string
|
||||
field :time, :naive_datetime
|
||||
field :location_id, :id
|
||||
field :performer_id, :id
|
||||
|
||||
timestamps()
|
||||
end
|
||||
|
||||
@doc false
|
||||
def changeset(performance, attrs) do
|
||||
performance
|
||||
|> cast(attrs, [:time, :description, :notes])
|
||||
|> validate_required([:time, :description, :notes])
|
||||
end
|
||||
end
|
||||
62
lib/runosaari_web/controllers/performance_controller.ex
Normal file
62
lib/runosaari_web/controllers/performance_controller.ex
Normal file
@@ -0,0 +1,62 @@
|
||||
defmodule RunosaariWeb.PerformanceController do
|
||||
use RunosaariWeb, :controller
|
||||
|
||||
alias Runosaari.Schedule
|
||||
alias Runosaari.Schedule.Performance
|
||||
|
||||
def index(conn, _params) do
|
||||
performances = Schedule.list_performances()
|
||||
render(conn, "index.html", performances: performances)
|
||||
end
|
||||
|
||||
def new(conn, _params) do
|
||||
changeset = Schedule.change_performance(%Performance{})
|
||||
render(conn, "new.html", changeset: changeset)
|
||||
end
|
||||
|
||||
def create(conn, %{"performance" => performance_params}) do
|
||||
case Schedule.create_performance(performance_params) do
|
||||
{:ok, performance} ->
|
||||
conn
|
||||
|> put_flash(:info, "Performance created successfully.")
|
||||
|> redirect(to: Routes.performance_path(conn, :show, performance))
|
||||
|
||||
{:error, %Ecto.Changeset{} = changeset} ->
|
||||
render(conn, "new.html", changeset: changeset)
|
||||
end
|
||||
end
|
||||
|
||||
def show(conn, %{"id" => id}) do
|
||||
performance = Schedule.get_performance!(id)
|
||||
render(conn, "show.html", performance: performance)
|
||||
end
|
||||
|
||||
def edit(conn, %{"id" => id}) do
|
||||
performance = Schedule.get_performance!(id)
|
||||
changeset = Schedule.change_performance(performance)
|
||||
render(conn, "edit.html", performance: performance, changeset: changeset)
|
||||
end
|
||||
|
||||
def update(conn, %{"id" => id, "performance" => performance_params}) do
|
||||
performance = Schedule.get_performance!(id)
|
||||
|
||||
case Schedule.update_performance(performance, performance_params) do
|
||||
{:ok, performance} ->
|
||||
conn
|
||||
|> put_flash(:info, "Performance updated successfully.")
|
||||
|> redirect(to: Routes.performance_path(conn, :show, performance))
|
||||
|
||||
{:error, %Ecto.Changeset{} = changeset} ->
|
||||
render(conn, "edit.html", performance: performance, changeset: changeset)
|
||||
end
|
||||
end
|
||||
|
||||
def delete(conn, %{"id" => id}) do
|
||||
performance = Schedule.get_performance!(id)
|
||||
{:ok, _performance} = Schedule.delete_performance(performance)
|
||||
|
||||
conn
|
||||
|> put_flash(:info, "Performance deleted successfully.")
|
||||
|> redirect(to: Routes.performance_path(conn, :index))
|
||||
end
|
||||
end
|
||||
5
lib/runosaari_web/templates/performance/edit.html.eex
Normal file
5
lib/runosaari_web/templates/performance/edit.html.eex
Normal file
@@ -0,0 +1,5 @@
|
||||
<h1>Edit Performance</h1>
|
||||
|
||||
<%= render "form.html", Map.put(assigns, :action, Routes.performance_path(@conn, :update, @performance)) %>
|
||||
|
||||
<span><%= link "Back", to: Routes.performance_path(@conn, :index) %></span>
|
||||
23
lib/runosaari_web/templates/performance/form.html.eex
Normal file
23
lib/runosaari_web/templates/performance/form.html.eex
Normal file
@@ -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, :time %>
|
||||
<%= datetime_select f, :time %>
|
||||
<%= error_tag f, :time %>
|
||||
|
||||
<%= label f, :description %>
|
||||
<%= text_input f, :description %>
|
||||
<%= error_tag f, :description %>
|
||||
|
||||
<%= label f, :notes %>
|
||||
<%= text_input f, :notes %>
|
||||
<%= error_tag f, :notes %>
|
||||
|
||||
<div>
|
||||
<%= submit "Save" %>
|
||||
</div>
|
||||
<% end %>
|
||||
30
lib/runosaari_web/templates/performance/index.html.eex
Normal file
30
lib/runosaari_web/templates/performance/index.html.eex
Normal file
@@ -0,0 +1,30 @@
|
||||
<h1>Listing Performances</h1>
|
||||
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Time</th>
|
||||
<th>Description</th>
|
||||
<th>Notes</th>
|
||||
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<%= for performance <- @performances do %>
|
||||
<tr>
|
||||
<td><%= performance.time %></td>
|
||||
<td><%= performance.description %></td>
|
||||
<td><%= performance.notes %></td>
|
||||
|
||||
<td>
|
||||
<span><%= link "Show", to: Routes.performance_path(@conn, :show, performance) %></span>
|
||||
<span><%= link "Edit", to: Routes.performance_path(@conn, :edit, performance) %></span>
|
||||
<span><%= link "Delete", to: Routes.performance_path(@conn, :delete, performance), method: :delete, data: [confirm: "Are you sure?"] %></span>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<span><%= link "New Performance", to: Routes.performance_path(@conn, :new) %></span>
|
||||
5
lib/runosaari_web/templates/performance/new.html.eex
Normal file
5
lib/runosaari_web/templates/performance/new.html.eex
Normal file
@@ -0,0 +1,5 @@
|
||||
<h1>New Performance</h1>
|
||||
|
||||
<%= render "form.html", Map.put(assigns, :action, Routes.performance_path(@conn, :create)) %>
|
||||
|
||||
<span><%= link "Back", to: Routes.performance_path(@conn, :index) %></span>
|
||||
23
lib/runosaari_web/templates/performance/show.html.eex
Normal file
23
lib/runosaari_web/templates/performance/show.html.eex
Normal file
@@ -0,0 +1,23 @@
|
||||
<h1>Show Performance</h1>
|
||||
|
||||
<ul>
|
||||
|
||||
<li>
|
||||
<strong>Time:</strong>
|
||||
<%= @performance.time %>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<strong>Description:</strong>
|
||||
<%= @performance.description %>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<strong>Notes:</strong>
|
||||
<%= @performance.notes %>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
||||
<span><%= link "Edit", to: Routes.performance_path(@conn, :edit, @performance) %></span>
|
||||
<span><%= link "Back", to: Routes.performance_path(@conn, :index) %></span>
|
||||
3
lib/runosaari_web/views/performance_view.ex
Normal file
3
lib/runosaari_web/views/performance_view.ex
Normal file
@@ -0,0 +1,3 @@
|
||||
defmodule RunosaariWeb.PerformanceView do
|
||||
use RunosaariWeb, :view
|
||||
end
|
||||
Reference in New Issue
Block a user