diff options
author | neodarz <neodarz@neodarz.net> | 2017-02-17 10:23:19 +0100 |
---|---|---|
committer | neodarz <neodarz@neodarz.net> | 2017-02-17 10:23:19 +0100 |
commit | 285cc8d28bc0cb42aed0a85b61b3b34a6b627264 (patch) | |
tree | cd4359d51579736c6b0af497a9d6612f1d44c822 /web | |
parent | 76392ebcfe772945be317d21e7b86364e3c4855c (diff) | |
download | the_transcriber_backend-285cc8d28bc0cb42aed0a85b61b3b34a6b627264.tar.xz the_transcriber_backend-285cc8d28bc0cb42aed0a85b61b3b34a6b627264.zip |
Add test if file is delete in database before delete the file
Diffstat (limited to '')
-rw-r--r-- | web/controllers/audio_file_controller.ex | 23 |
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 |