From e748d11bfd2232b77aeb5dae0d1e76ebb2988afb Mon Sep 17 00:00:00 2001 From: neodarz Date: Thu, 9 Feb 2017 14:07:40 +0100 Subject: Update the column name transcrib_file to audio_name --- .../20170124112342_create_audio_file.exs | 14 ------------- .../20170209113547_create_audio_file.exs | 14 +++++++++++++ test/controllers/audio_file_controller_test.exs | 2 +- test/models/audio_file_test.exs | 2 +- web/controllers/audio_file_api_controller.ex | 4 ++-- web/controllers/audio_file_controller.ex | 23 +++++++++++++++------- web/models/audio_file.ex | 6 +++--- web/models/audio_file_api.ex | 2 +- web/templates/audio_file/form.html.eex | 6 +++--- web/templates/audio_file/index.html.eex | 2 +- web/templates/audio_file/show.html.eex | 2 +- web/views/audio_file_api_view.ex | 2 +- web/views/audio_file_view.ex | 2 +- 13 files changed, 45 insertions(+), 36 deletions(-) delete mode 100644 priv/repo/migrations/20170124112342_create_audio_file.exs create mode 100644 priv/repo/migrations/20170209113547_create_audio_file.exs diff --git a/priv/repo/migrations/20170124112342_create_audio_file.exs b/priv/repo/migrations/20170124112342_create_audio_file.exs deleted file mode 100644 index 0fdac43..0000000 --- a/priv/repo/migrations/20170124112342_create_audio_file.exs +++ /dev/null @@ -1,14 +0,0 @@ -defmodule TheTranscriberBackend.Repo.Migrations.CreateAudioFile do - use Ecto.Migration - - def change do - create table(:audio_file) do - add :audio_path, :string - add :transcription_file_path, :string - add :audio_duration, :string - - timestamps() - end - - end -end diff --git a/priv/repo/migrations/20170209113547_create_audio_file.exs b/priv/repo/migrations/20170209113547_create_audio_file.exs new file mode 100644 index 0000000..6f00b38 --- /dev/null +++ b/priv/repo/migrations/20170209113547_create_audio_file.exs @@ -0,0 +1,14 @@ +defmodule TheTranscriberBackend.Repo.Migrations.CreateAudioFile do + use Ecto.Migration + + def change do + create table(:audio_file) do + add :audio_path, :string + add :audio_name, :string + add :audio_duration, :string + + timestamps() + end + + end +end diff --git a/test/controllers/audio_file_controller_test.exs b/test/controllers/audio_file_controller_test.exs index e1df494..8c2b9d6 100644 --- a/test/controllers/audio_file_controller_test.exs +++ b/test/controllers/audio_file_controller_test.exs @@ -2,7 +2,7 @@ defmodule TheTranscriberBackend.AudioFileControllerTest do use TheTranscriberBackend.ConnCase alias TheTranscriberBackend.AudioFile - @valid_attrs %{audio_duration: "some content", audio_path: "some content", transcription_file_path: "some content"} + @valid_attrs %{audio_duration: "some content", audio_path: "some content", audio_name: "some content"} @invalid_attrs %{} test "lists all entries on index", %{conn: conn} do diff --git a/test/models/audio_file_test.exs b/test/models/audio_file_test.exs index 749cf4e..c9e0189 100644 --- a/test/models/audio_file_test.exs +++ b/test/models/audio_file_test.exs @@ -3,7 +3,7 @@ defmodule TheTranscriberBackend.AudioFileTest do alias TheTranscriberBackend.AudioFile - @valid_attrs %{audio_duration: "some content", audio_path: "some content", transcription_file_path: "some content"} + @valid_attrs %{audio_duration: "some content", audio_path: "some content", audio_name: "some content"} @invalid_attrs %{} test "changeset with valid attributes" do 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 @@
- <%= 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 %>
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 %> <%= audio_file.audio_path %> - <%= audio_file.transcription_file_path %> + <%= audio_file.audio_name %> <%= audio_file.audio_duration %> 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 @@
  • Transcription file path: - <%= @audio_file.transcription_file_path %> + <%= @audio_file.audio_name %>
  • 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 -- cgit v1.2.1