aboutsummaryrefslogtreecommitdiff
path: root/web/controllers/audio_file_controller.ex
diff options
context:
space:
mode:
Diffstat (limited to 'web/controllers/audio_file_controller.ex')
-rw-r--r--web/controllers/audio_file_controller.ex23
1 files changed, 15 insertions, 8 deletions
diff --git a/web/controllers/audio_file_controller.ex b/web/controllers/audio_file_controller.ex
index 2c34e86..784c92c 100644
--- a/web/controllers/audio_file_controller.ex
+++ b/web/controllers/audio_file_controller.ex
@@ -78,15 +78,22 @@ defmodule TheTranscriberBackend.AudioFileController do
end
def delete(conn, %{"id" => id}) do
+ path = "/media/phoenix_test/"
audio_file = Repo.get!(AudioFile, id)
+ cond do
+ audio_file !=nil ->
+ # Here we use delete! (with a bang) because we expect
+ # it to always work (and if it does not, it will raise).
+ File.rm("#{path}#{audio_file.id}_#{audio_file.audio_path}")
+ Repo.delete!(audio_file)
- # Here we use delete! (with a bang) because we expect
- # it to always work (and if it does not, it will raise).
- File.rm(audio_file.audio_path)
- Repo.delete!(audio_file)
-
- conn
- |> put_flash(:info, "Audio file deleted successfully.")
- |> redirect(to: audio_file_path(conn, :index))
+ conn
+ |> put_flash(:info, "Audio file deleted successfully.")
+ |> redirect(to: audio_file_path(conn, :index))
+ audio_file == nil ->
+ conn
+ |> put_flash(:info, "File not found in database !")
+ |> redirect(to: audio_file_path(conn, :index))
+ end
end
end