aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorneodarz <neodarz@neodarz.net>2017-02-09 14:12:24 +0100
committerneodarz <neodarz@neodarz.net>2017-02-09 14:12:24 +0100
commitbaee9be0edae229e46a3b8f438b7b4a3022a84f3 (patch)
treef6bd74d753f381aa405306e3a3c3c01ca08c3ce0
parente748d11bfd2232b77aeb5dae0d1e76ebb2988afb (diff)
downloadthe_transcriber_backend-baee9be0edae229e46a3b8f438b7b4a3022a84f3.tar.xz
the_transcriber_backend-baee9be0edae229e46a3b8f438b7b4a3022a84f3.zip
Fix error when the table is empty
-rw-r--r--web/controllers/audio_file_controller.ex10
1 files changed, 3 insertions, 7 deletions
diff --git a/web/controllers/audio_file_controller.ex b/web/controllers/audio_file_controller.ex
index 42aa7e7..ef9d46c 100644
--- a/web/controllers/audio_file_controller.ex
+++ b/web/controllers/audio_file_controller.ex
@@ -15,13 +15,9 @@ defmodule TheTranscriberBackend.AudioFileController do
def create(conn, %{"audio_file" => %{"audio_duration" => audio_duration, "audio_path" => upload, "audio_name" => audio_name}}) do
- repo_last_id = Repo.one(from x in AudioFile, order_by: [desc: x.id], limit: 1)
-
- #query = "select nextval('audio_file_id_seq')"
-
- #result = Ecto.Adapters.SQL.query!(Repo, query, [])
-
- #[[repo_last_id]] = result.rows # A beautiful pattern match :)
+ query = "select nextval('audio_file_id_seq')"
+ result = Ecto.Adapters.SQL.query!(Repo, query, [])
+ [[repo_last_id]] = result.rows # A beautiful pattern match :)
path = "/media/phoenix_test/#{repo_last_id}_#{upload.filename}"
File.cp(upload.path, path)