diff options
author | neodarz <neodarz@neodarz.net> | 2017-02-09 14:07:40 +0100 |
---|---|---|
committer | neodarz <neodarz@neodarz.net> | 2017-02-09 14:07:40 +0100 |
commit | e748d11bfd2232b77aeb5dae0d1e76ebb2988afb (patch) | |
tree | a30329b2fbab4dd583761f729f20d7bffa447cf9 /web/controllers | |
parent | e455009b1872815c4fad91c389af9f7a27a6ba28 (diff) | |
download | the_transcriber_backend-e748d11bfd2232b77aeb5dae0d1e76ebb2988afb.tar.xz the_transcriber_backend-e748d11bfd2232b77aeb5dae0d1e76ebb2988afb.zip |
Update the column name transcrib_file to audio_name
Diffstat (limited to '')
-rw-r--r-- | web/controllers/audio_file_api_controller.ex | 4 | ||||
-rw-r--r-- | web/controllers/audio_file_controller.ex | 23 |
2 files changed, 18 insertions, 9 deletions
diff --git a/web/controllers/audio_file_api_controller.ex b/web/controllers/audio_file_api_controller.ex index 65b968c..5e97c9c 100644 --- a/web/controllers/audio_file_api_controller.ex +++ b/web/controllers/audio_file_api_controller.ex @@ -9,7 +9,7 @@ defmodule TheTranscriberBackend.AudioFileAPIController do render(conn, "index.json", audio_file_api: audio_file_api) end - def create(conn, %{"audio_file" => %{"audio_duration" => audio_duration, "audio_path" => upload, "transcription_file_path" => transcription_file_path}}) 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 AudioFileAPI, order_by: [desc: x.id], limit: 1)).id @@ -18,7 +18,7 @@ defmodule TheTranscriberBackend.AudioFileAPIController do changeset = AudioFile.changeset(%AudioFile{}, %{audio_path: path, - transcription_file_path: transcription_file_path, + audio_name: audio_name, audio_duration: audio_duration}) IO.inspect path diff --git a/web/controllers/audio_file_controller.ex b/web/controllers/audio_file_controller.ex index 1c2acb9..42aa7e7 100644 --- a/web/controllers/audio_file_controller.ex +++ b/web/controllers/audio_file_controller.ex @@ -13,14 +13,22 @@ defmodule TheTranscriberBackend.AudioFileController do render(conn, "new.html", changeset: changeset) end - def create(conn, %{"audio_file" => %{"audio_duration" => audio_duration, "audio_path" => upload, "transcription_file_path" => transcription_file_path}}) do + def create(conn, %{"audio_file" => %{"audio_duration" => audio_duration, "audio_path" => upload, "audio_name" => audio_name}}) do - path = "/media/phoenix_test/#{upload.filename}" + 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 :) + + path = "/media/phoenix_test/#{repo_last_id}_#{upload.filename}" File.cp(upload.path, path) changeset = AudioFile.changeset(%AudioFile{}, %{audio_path: path, - transcription_file_path: transcription_file_path, + audio_name: audio_name, audio_duration: audio_duration}) case Repo.insert(changeset) do @@ -35,7 +43,7 @@ defmodule TheTranscriberBackend.AudioFileController do -# def create(conn, %{"audio_file" => %{"audio_duration" => audio_duration, "transcription_file_path" => transcription_file_path}}) do +# def create(conn, %{"audio_file" => %{"audio_duration" => audio_duration, "audio_name" => audio_name}}) do # # ## Do something here if no file has been uploaded # end @@ -51,9 +59,10 @@ defmodule TheTranscriberBackend.AudioFileController do render(conn, "edit.html", audio_file: audio_file, changeset: changeset) end - def update(conn, %{"id" => id, "audio_file" => %{"audio_duration" => audio_duration, "audio_path" => upload, "transcription_file_path" => transcription_file_path}}) do + def update(conn, %{"id" => id, "audio_file" => %{"audio_duration" => audio_duration, "audio_path" => upload, "audio_name" => audio_name}}) do + + path = "/media/phoenix_test/#{id}_#{upload.filename}" - path = "/media/phoenix_test/#{upload.filename}" File.cp(upload.path, path) audio_file = Repo.get!(AudioFile, id) @@ -61,7 +70,7 @@ defmodule TheTranscriberBackend.AudioFileController do changeset = AudioFile.changeset(audio_file, %{audio_path: path, - transcription_file_path: transcription_file_path, + audio_name: audio_name, audio_duration: audio_duration}) case Repo.update(changeset) do |