fp/services/bright/lib/bright_web/controllers/vod_controller.ex

63 lines
1.5 KiB
Elixir

defmodule BrightWeb.VodController do
use BrightWeb, :controller
alias Bright.Streams
alias Bright.Streams.Vod
def index(conn, _params) do
vods = Streams.list_vods()
render(conn, :index, vods: vods)
end
def new(conn, _params) do
changeset = Streams.change_vod(%Vod{})
render(conn, :new, changeset: changeset)
end
def create(conn, %{"vod" => vod_params}) do
case Streams.create_vod(vod_params) do
{:ok, vod} ->
conn
|> put_flash(:info, "Vod created successfully.")
|> redirect(to: ~p"/vods/#{vod}")
{:error, %Ecto.Changeset{} = changeset} ->
render(conn, :new, changeset: changeset)
end
end
def show(conn, %{"id" => id}) do
vod = Streams.get_vod!(id)
render(conn, :show, vod: vod)
end
def edit(conn, %{"id" => id}) do
vod = Streams.get_vod!(id)
changeset = Streams.change_vod(vod)
render(conn, :edit, vod: vod, changeset: changeset)
end
def update(conn, %{"id" => id, "vod" => vod_params}) do
vod = Streams.get_vod!(id)
case Streams.update_vod(vod, vod_params) do
{:ok, vod} ->
conn
|> put_flash(:info, "Vod updated successfully.")
|> redirect(to: ~p"/vods/#{vod}")
{:error, %Ecto.Changeset{} = changeset} ->
render(conn, :edit, vod: vod, changeset: changeset)
end
end
def delete(conn, %{"id" => id}) do
vod = Streams.get_vod!(id)
{:ok, _vod} = Streams.delete_vod(vod)
conn
|> put_flash(:info, "Vod deleted successfully.")
|> redirect(to: ~p"/vods")
end
end