From 120bf89930ce7e136ba0b0499bce7b0f8b95f296 Mon Sep 17 00:00:00 2001 From: neodarz Date: Mon, 6 Feb 2017 16:52:00 +0100 Subject: Add a not secure function for upload files with curl --- web/views/audio_file_api_view.ex | 20 ++++++++++++++++++++ web/views/audio_file_view.ex | 5 +++++ web/views/changeset_view.ex | 19 +++++++++++++++++++ 3 files changed, 44 insertions(+) create mode 100644 web/views/audio_file_api_view.ex create mode 100644 web/views/changeset_view.ex (limited to 'web/views') diff --git a/web/views/audio_file_api_view.ex b/web/views/audio_file_api_view.ex new file mode 100644 index 0000000..f5dbba9 --- /dev/null +++ b/web/views/audio_file_api_view.ex @@ -0,0 +1,20 @@ +defmodule TheTranscriberBackend.AudioFileAPIView do + use TheTranscriberBackend.Web, :view + + + + def render("index.json", %{audio_file_api: audio_file_api}) do + %{data: render_many(audio_file_api, TheTranscriberBackend.AudioFileAPIView, "audio_file_api.json")} + end + + def render("show.json", %{audio_file_api: audio_file_api}) do + %{data: render_one(audio_file_api, TheTranscriberBackend.AudioFileAPIView, "audio_file_api.json")} + end + + 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_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 b2b2c26..8cefe83 100644 --- a/web/views/audio_file_view.ex +++ b/web/views/audio_file_view.ex @@ -1,3 +1,8 @@ defmodule TheTranscriberBackend.AudioFileView do use TheTranscriberBackend.Web, :view + + #attributes [:id, :audio_path, :transcription_file_path, :audio_duration] + + #has_many :audio_file_api, link + end diff --git a/web/views/changeset_view.ex b/web/views/changeset_view.ex new file mode 100644 index 0000000..767756e --- /dev/null +++ b/web/views/changeset_view.ex @@ -0,0 +1,19 @@ +defmodule TheTranscriberBackend.ChangesetView do + use TheTranscriberBackend.Web, :view + + @doc """ + Traverses and translates changeset errors. + + See `Ecto.Changeset.traverse_errors/2` and + `TheTranscriberBackend.ErrorHelpers.translate_error/1` for more details. + """ + def translate_errors(changeset) do + Ecto.Changeset.traverse_errors(changeset, &translate_error/1) + end + + def render("error.json", %{changeset: changeset}) do + # When encoded, the changeset returns its errors + # as a JSON object. So we just pass it forward. + %{errors: translate_errors(changeset)} + end +end -- cgit v1.2.1