diff options
Diffstat (limited to '')
-rw-r--r-- | web/controllers/audio_file_controller.ex | 65 | ||||
-rw-r--r-- | web/controllers/page_controller.ex | 7 |
2 files changed, 72 insertions, 0 deletions
diff --git a/web/controllers/audio_file_controller.ex b/web/controllers/audio_file_controller.ex new file mode 100644 index 0000000..8cf5a00 --- /dev/null +++ b/web/controllers/audio_file_controller.ex @@ -0,0 +1,65 @@ +defmodule TheTranscriberBackend.AudioFileController do + use TheTranscriberBackend.Web, :controller + + alias TheTranscriberBackend.AudioFile + + def index(conn, _params) do + audio_file = Repo.all(AudioFile) + render(conn, "index.html", audio_file: audio_file) + end + + def new(conn, _params) do + changeset = AudioFile.changeset(%AudioFile{}) + render(conn, "new.html", changeset: changeset) + end + + def create(conn, %{"audio_file" => audio_file_params}) do + changeset = AudioFile.changeset(%AudioFile{}, audio_file_params) + + case Repo.insert(changeset) do + {:ok, _audio_file} -> + conn + |> put_flash(:info, "Audio file created successfully.") + |> redirect(to: audio_file_path(conn, :index)) + {:error, changeset} -> + render(conn, "new.html", changeset: changeset) + end + end + + def show(conn, %{"id" => id}) do + audio_file = Repo.get!(AudioFile, id) + render(conn, "show.html", audio_file: audio_file) + end + + def edit(conn, %{"id" => id}) do + audio_file = Repo.get!(AudioFile, id) + changeset = AudioFile.changeset(audio_file) + render(conn, "edit.html", audio_file: audio_file, changeset: changeset) + end + + def update(conn, %{"id" => id, "audio_file" => audio_file_params}) do + audio_file = Repo.get!(AudioFile, id) + changeset = AudioFile.changeset(audio_file, audio_file_params) + + case Repo.update(changeset) do + {:ok, audio_file} -> + conn + |> put_flash(:info, "Audio file updated successfully.") + |> redirect(to: audio_file_path(conn, :show, audio_file)) + {:error, changeset} -> + render(conn, "edit.html", audio_file: audio_file, changeset: changeset) + end + end + + def delete(conn, %{"id" => id}) do + audio_file = Repo.get!(AudioFile, id) + + # Here we use delete! (with a bang) because we expect + # it to always work (and if it does not, it will raise). + Repo.delete!(audio_file) + + conn + |> put_flash(:info, "Audio file deleted successfully.") + |> redirect(to: audio_file_path(conn, :index)) + end +end diff --git a/web/controllers/page_controller.ex b/web/controllers/page_controller.ex new file mode 100644 index 0000000..996b05b --- /dev/null +++ b/web/controllers/page_controller.ex @@ -0,0 +1,7 @@ +defmodule TheTranscriberBackend.PageController do + use TheTranscriberBackend.Web, :controller + + def index(conn, _params) do + render conn, "index.html" + end +end |