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

63 lines
1.7 KiB
Elixir
Raw Normal View History

2025-01-03 14:45:35 +00:00
defmodule BrightWeb.VtuberController do
use BrightWeb, :controller
alias Bright.Vtubers
alias Bright.Vtubers.Vtuber
def index(conn, _params) do
vtubers = Vtubers.list_vtubers()
render(conn, :index, vtubers: vtubers)
end
def new(conn, _params) do
changeset = Vtubers.change_vtuber(%Vtuber{})
render(conn, :new, changeset: changeset)
end
def create(conn, %{"vtuber" => vtuber_params}) do
case Vtubers.create_vtuber(vtuber_params) do
{:ok, vtuber} ->
conn
|> put_flash(:info, "Vtuber created successfully.")
|> redirect(to: ~p"/vtubers/#{vtuber}")
{:error, %Ecto.Changeset{} = changeset} ->
render(conn, :new, changeset: changeset)
end
end
def show(conn, %{"id" => id}) do
vtuber = Vtubers.get_vtuber!(id)
render(conn, :show, vtuber: vtuber)
end
def edit(conn, %{"id" => id}) do
vtuber = Vtubers.get_vtuber!(id)
changeset = Vtubers.change_vtuber(vtuber)
render(conn, :edit, vtuber: vtuber, changeset: changeset)
end
def update(conn, %{"id" => id, "vtuber" => vtuber_params}) do
vtuber = Vtubers.get_vtuber!(id)
case Vtubers.update_vtuber(vtuber, vtuber_params) do
{:ok, vtuber} ->
conn
|> put_flash(:info, "Vtuber updated successfully.")
|> redirect(to: ~p"/vtubers/#{vtuber}")
{:error, %Ecto.Changeset{} = changeset} ->
render(conn, :edit, vtuber: vtuber, changeset: changeset)
end
end
def delete(conn, %{"id" => id}) do
vtuber = Vtubers.get_vtuber!(id)
{:ok, _vtuber} = Vtubers.delete_vtuber(vtuber)
conn
|> put_flash(:info, "Vtuber deleted successfully.")
|> redirect(to: ~p"/vtubers")
end
end