From 17bee7da8a376706f7fc1dd2574f6b8e5190df62 Mon Sep 17 00:00:00 2001 From: Marcos Vanetta Date: Tue, 3 Feb 2015 15:59:33 -0600 Subject: [PATCH] [aphrodite] Closing #218 --- .../api/v2/documents_controller.rb | 4 ++-- .../views/api/v2/documents/shared.json.rabl | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 aphrodite/app/views/api/v2/documents/shared.json.rabl diff --git a/aphrodite/app/controllers/api/v2/documents_controller.rb b/aphrodite/app/controllers/api/v2/documents_controller.rb index 4ce00fb3..e55950e8 100644 --- a/aphrodite/app/controllers/api/v2/documents_controller.rb +++ b/aphrodite/app/controllers/api/v2/documents_controller.rb @@ -28,7 +28,7 @@ def links uploader = LinksUploaderService.new(params[:bucket], current_user) if uploader.valid? @documents = uploader.call - render :index + render :shared else render json: { error_messages: { files_limit: "Ha excedido el límite de documentos"} @@ -41,7 +41,7 @@ def create uploader = DocumentUploaderService.new(files, current_user) if uploader.valid? @documents = uploader.call - render :index + render :shared else render json: {error_messages: { files_limit: "Ha excedido el límite de documentos"}}, status: 403 end diff --git a/aphrodite/app/views/api/v2/documents/shared.json.rabl b/aphrodite/app/views/api/v2/documents/shared.json.rabl new file mode 100644 index 00000000..34ff653b --- /dev/null +++ b/aphrodite/app/views/api/v2/documents/shared.json.rabl @@ -0,0 +1,19 @@ +collection @documents +attributes :id, :title, :created_at, :percentage, :url + +node :counters do |document| + { + people: document.context_cache.fetch('people', []).count, + organizations: document.context_cache.fetch('organizations', []).count, + places: document.context_cache.fetch('places', []).count, + dates: document.context_cache.fetch('dates', []).count + } +end + +node :failed do |document| + !document.valid? +end + +node :error_messages do |document| + document.errors.messages +end