aboutsummaryrefslogtreecommitdiff
path: root/web
diff options
context:
space:
mode:
Diffstat (limited to 'web')
-rw-r--r--web/controllers/audio_file_api_controller.ex4
-rw-r--r--web/controllers/audio_file_controller.ex23
-rw-r--r--web/models/audio_file.ex6
-rw-r--r--web/models/audio_file_api.ex2
-rw-r--r--web/templates/audio_file/form.html.eex6
-rw-r--r--web/templates/audio_file/index.html.eex2
-rw-r--r--web/templates/audio_file/show.html.eex2
-rw-r--r--web/views/audio_file_api_view.ex2
-rw-r--r--web/views/audio_file_view.ex2
9 files changed, 29 insertions, 20 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
diff --git a/web/models/audio_file.ex b/web/models/audio_file.ex
index 46cf05f..f7be8de 100644
--- a/web/models/audio_file.ex
+++ b/web/models/audio_file.ex
@@ -3,7 +3,7 @@ defmodule TheTranscriberBackend.AudioFile do
schema "audio_file" do
field :audio_path, :string
- field :transcription_file_path, :string
+ field :audio_name, :string
field :audio_duration, :string
timestamps()
@@ -15,7 +15,7 @@ defmodule TheTranscriberBackend.AudioFile do
def changeset(struct, params \\ %{}) do
struct
- |> cast(params, [:audio_path, :transcription_file_path, :audio_duration])
- |> validate_required([:audio_path, :transcription_file_path, :audio_duration])
+ |> cast(params, [:audio_path, :audio_name, :audio_duration])
+ |> validate_required([:audio_path, :audio_name, :audio_duration])
end
end
diff --git a/web/models/audio_file_api.ex b/web/models/audio_file_api.ex
index 15f2e42..802d179 100644
--- a/web/models/audio_file_api.ex
+++ b/web/models/audio_file_api.ex
@@ -6,7 +6,7 @@ defmodule TheTranscriberBackend.AudioFileAPI do
schema "audio_file" do
field :audio_path, :string
- field :transcription_file_path, :string
+ field :audio_name, :string
field :audio_duration, :string
timestamps()
diff --git a/web/templates/audio_file/form.html.eex b/web/templates/audio_file/form.html.eex
index 2667f23..32d6b5c 100644
--- a/web/templates/audio_file/form.html.eex
+++ b/web/templates/audio_file/form.html.eex
@@ -12,9 +12,9 @@
</div>
<div class="form-group">
- <%= label f, :transcription_file_path, class: "control-label" %>
- <%= text_input f, :transcription_file_path, class: "form-control" %>
- <%= error_tag f, :transcription_file_path %>
+ <%= label f, :audio_name, class: "control-label" %>
+ <%= text_input f, :audio_name, class: "form-control" %>
+ <%= error_tag f, :audio_name %>
</div>
<div class="form-group">
diff --git a/web/templates/audio_file/index.html.eex b/web/templates/audio_file/index.html.eex
index 445178d..59b73a9 100644
--- a/web/templates/audio_file/index.html.eex
+++ b/web/templates/audio_file/index.html.eex
@@ -14,7 +14,7 @@
<%= for audio_file <- @audio_file do %>
<tr>
<td><%= audio_file.audio_path %></td>
- <td><%= audio_file.transcription_file_path %></td>
+ <td><%= audio_file.audio_name %></td>
<td><%= audio_file.audio_duration %></td>
<td class="text-right">
diff --git a/web/templates/audio_file/show.html.eex b/web/templates/audio_file/show.html.eex
index 2cc05d4..ea841f0 100644
--- a/web/templates/audio_file/show.html.eex
+++ b/web/templates/audio_file/show.html.eex
@@ -9,7 +9,7 @@
<li>
<strong>Transcription file path:</strong>
- <%= @audio_file.transcription_file_path %>
+ <%= @audio_file.audio_name %>
</li>
<li>
diff --git a/web/views/audio_file_api_view.ex b/web/views/audio_file_api_view.ex
index f5dbba9..1042be0 100644
--- a/web/views/audio_file_api_view.ex
+++ b/web/views/audio_file_api_view.ex
@@ -14,7 +14,7 @@ defmodule TheTranscriberBackend.AudioFileAPIView do
def render("audio_file_api.json", %{audio_file_api: audio_file_api}) do
%{id: audio_file_api.id,
audio_path: audio_file_api.audio_path,
- audio_transcription_file_path: audio_file_api.transcription_file_path,
+ audio_name: audio_file_api.audio_name,
audio_duration: audio_file_api.audio_duration}
end
end
diff --git a/web/views/audio_file_view.ex b/web/views/audio_file_view.ex
index 8cefe83..aa9c742 100644
--- a/web/views/audio_file_view.ex
+++ b/web/views/audio_file_view.ex
@@ -1,7 +1,7 @@
defmodule TheTranscriberBackend.AudioFileView do
use TheTranscriberBackend.Web, :view
- #attributes [:id, :audio_path, :transcription_file_path, :audio_duration]
+ #attributes [:id, :audio_path, :audio_name, :audio_duration]
#has_many :audio_file_api, link