diff options
author | Vincent Jousse <vincent@jousse.org> | 2017-01-25 17:44:50 +0100 |
---|---|---|
committer | Vincent Jousse <vincent@jousse.org> | 2017-01-25 17:44:50 +0100 |
commit | 84ea469e79f71929aa55b6e9e60fe53042bb7808 (patch) | |
tree | 6b84998a8f7c31dcdc4c961a30560ab7b1812cb1 /web/controllers | |
parent | 532c3a6538d3cc5916cb5bafeaab931164089e20 (diff) | |
download | the_transcriber_backend-84ea469e79f71929aa55b6e9e60fe53042bb7808.tar.xz the_transcriber_backend-84ea469e79f71929aa55b6e9e60fe53042bb7808.zip |
Use pattern-matching to handle different cases
Diffstat (limited to '')
-rw-r--r-- | web/controllers/audio_file_controller.ex | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/web/controllers/audio_file_controller.ex b/web/controllers/audio_file_controller.ex index c32a7f8..dbcb6f9 100644 --- a/web/controllers/audio_file_controller.ex +++ b/web/controllers/audio_file_controller.ex @@ -13,18 +13,16 @@ defmodule TheTranscriberBackend.AudioFileController do render(conn, "new.html", changeset: changeset) end - def create(conn, %{"audio_file" => audio_file_params}) do - if upload = audio_file_params["audio_path"] do - extension = Path.extname(upload.filename) - path = "/media/phoenix_test/#{upload.filename}" - File.cp(upload.path, path) - end + def create(conn, %{"audio_file" => %{"audio_duration" => audio_duration, "audio_path" => upload, "transcription_file_path" => transcription_file_path}}) do + + path = "/media/phoenix_test/#{upload.filename}" + File.cp(upload.path, path) # "Non-elixir" way of doing things changeset = AudioFile.changeset(%AudioFile{}, %{audio_path: path, - transcription_file_path: audio_file_params["transcription_file_path"], - audio_duration: audio_file_params["audio_duration"]}) + transcription_file_path: transcription_file_path, + audio_duration: audio_duration}) IO.inspect changeset @@ -38,6 +36,13 @@ defmodule TheTranscriberBackend.AudioFileController do end end + + + def create(conn, %{"audio_file" => %{"audio_duration" => audio_duration, "transcription_file_path" => transcription_file_path}}) do + + ## Do something here if no file has been uploaded + end + def show(conn, %{"id" => id}) do audio_file = Repo.get!(AudioFile, id) render(conn, "show.html", audio_file: audio_file) |