aboutsummaryrefslogtreecommitdiff
path: root/web
diff options
context:
space:
mode:
authorneodarz <neodarz@neodarz.net>2017-03-10 12:03:01 +0100
committerneodarz <neodarz@neodarz.net>2017-03-10 12:03:01 +0100
commitdd8662ed25467fe06ca8132a998b8d1409b0af65 (patch)
tree1eadd79137ba7647d4c026898efe0806c99939fb /web
parent9c5a3c3b5e905bbf5934a2e9630585502c14cfdc (diff)
downloadthe_transcriber_backend-dd8662ed25467fe06ca8132a998b8d1409b0af65.tar.xz
the_transcriber_backend-dd8662ed25467fe06ca8132a998b8d1409b0af65.zip
update for fix test & add fictive shell command
Diffstat (limited to 'web')
-rw-r--r--web/controllers/audio_file_api_controller.ex54
1 files changed, 43 insertions, 11 deletions
diff --git a/web/controllers/audio_file_api_controller.ex b/web/controllers/audio_file_api_controller.ex
index 436c6e9..4587596 100644
--- a/web/controllers/audio_file_api_controller.ex
+++ b/web/controllers/audio_file_api_controller.ex
@@ -17,9 +17,12 @@ defmodule TheTranscriberBackend.AudioFileAPIController do
audio_name: audio_name,
audio_duration: "#{FFprobe.duration(upload.path)}"})
+
+
case Repo.insert(changeset) do
{:ok, audio_file_api} ->
File.cp(upload.path, "#{path}#{audio_file_api.id}_#{upload.filename}")
+ System.cmd "notify-send", ["Yeah ! Your file is uploaded !"]
conn
|> put_status(:created)
@@ -37,19 +40,48 @@ defmodule TheTranscriberBackend.AudioFileAPIController do
render(conn, "show.json", audio_file_api: audio_file_api)
end
- def update(conn, %{"id" => id, "audio_file_api" => audio_file_api_params}) do
- audio_file_api = Repo.get!(AudioFileAPI, id)
- changeset = AudioFileAPI.changeset(audio_file_api, audio_file_api_params)
+# def update(conn, %{"id" => id, "audio_file_api" => audio_file_api_params}) do
+# audio_file_api = Repo.get!(AudioFileAPI, id)
+# changeset = AudioFileAPI.changeset(audio_file_api, audio_file_api_params)
+#
+# case Repo.update(changeset) do
+# {:ok, audio_file_api} ->
+# render(conn, "show.json", audio_file_api: audio_file_api)
+# {:error, changeset} ->
+# conn
+# |> put_status(:unprocessable_entity)
+# |> render(TheTranscriberBackend.ChangesetView, "error.json", changeset: changeset)
+# end
+# end
- case Repo.update(changeset) do
- {:ok, audio_file_api} ->
- render(conn, "show.json", audio_file_api: audio_file_api)
- {:error, changeset} ->
- conn
- |> put_status(:unprocessable_entity)
- |> render(TheTranscriberBackend.ChangesetView, "error.json", changeset: changeset)
- end
+def update(conn, %{"id" => id, "audio_file" => %{"audio_path" => upload, "audio_name" => audio_name}}) do
+ path = "/media/phoenix_test/"
+ audio_file = Repo.get!(AudioFileAPI, id)
+ #changeset = AudioFile.changeset(audio_file, audio_file_params)
+
+
+
+ changeset = AudioFileAPI.changeset(audio_file,
+ %{audio_path: upload.filename,
+ audio_name: audio_name,
+ audio_duration: "#{FFprobe.duration(upload.path)}"})
+
+
+
+ case Repo.update(changeset) do
+ {:ok, audio_file_api} ->
+ File.cp(upload.path, "#{path}#{audio_file_api.id}_#{upload.filename}")
+ IO.inspect audio_file_api
+ conn
+ |> put_status(:created)
+ |> put_resp_header("location", audio_file_api_path(conn, :show, audio_file_api))
+ |> render("show.json", audio_file_api: audio_file_api)
+ {:error, changeset} ->
+ conn
+ |> put_status(:unprocessable_entity)
+ |> render(TheTranscriberBackend.ChangesetView, "error.json", changeset: changeset)
end
+end
def delete(conn, %{"id" => id}) do
path = "/media/phoenix_test/"