From 822c7cdd96380a45f760cc7c55eec77b56894ea3 Mon Sep 17 00:00:00 2001 From: Mathieu Magnin Date: Fri, 14 Apr 2017 17:38:08 +0200 Subject: [PATCH] Add human version translation for state --- app/controllers/api/v1/dossiers_controller.rb | 4 ++-- app/models/dossier.rb | 1 - app/serializers/dossier_serializer.rb | 7 ++++++- doc/apipie_examples.json | 4 +++- spec/controllers/api/v1/dossiers_controller_spec.rb | 2 +- 5 files changed, 12 insertions(+), 6 deletions(-) diff --git a/app/controllers/api/v1/dossiers_controller.rb b/app/controllers/api/v1/dossiers_controller.rb index 9f5ae7672..e77e11351 100644 --- a/app/controllers/api/v1/dossiers_controller.rb +++ b/app/controllers/api/v1/dossiers_controller.rb @@ -13,7 +13,7 @@ class API::V1::DossiersController < APIController procedure = current_administrateur.procedures.find(params[:procedure_id]) dossiers = procedure.dossiers.where.not(state: :draft).paginate(page: params[:page]) - render json: {dossiers: dossiers.map{|dossier| DossiersSerializer.new(dossier)}, pagination: pagination(dossiers)}, status: 200 + render json: { dossiers: dossiers.map{ |dossier| DossiersSerializer.new(dossier) }, pagination: pagination(dossiers) }, status: 200 rescue ActiveRecord::RecordNotFound render json: {}, status: 404 end @@ -34,7 +34,7 @@ class API::V1::DossiersController < APIController dossier = procedure.dossiers.find(params[:id]) respond_to do |format| - format.json { render json: {dossier: DossierSerializer.new(dossier).as_json}, status: 200 } + format.json { render json: { dossier: DossierSerializer.new(dossier).as_json }, status: 200 } end rescue ActiveRecord::RecordNotFound render json: {}, status: 404 diff --git a/app/models/dossier.rb b/app/models/dossier.rb index 907fe7323..5fc523452 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -292,5 +292,4 @@ class Dossier < ActiveRecord::Base def serialize_value_for_export(value) value.nil? || value.kind_of?(Time) ? value : value.to_s end - end diff --git a/app/serializers/dossier_serializer.rb b/app/serializers/dossier_serializer.rb index eb074761b..41336c6cf 100644 --- a/app/serializers/dossier_serializer.rb +++ b/app/serializers/dossier_serializer.rb @@ -4,7 +4,8 @@ class DossierSerializer < ActiveModel::Serializer :updated_at, :archived, :mandataire_social, - :state + :state, + :simplified_state has_one :entreprise has_one :etablissement @@ -14,4 +15,8 @@ class DossierSerializer < ActiveModel::Serializer has_many :champs_private has_many :pieces_justificatives has_many :types_de_piece_justificative + + def simplified_state + object.decorate.display_state + end end diff --git a/doc/apipie_examples.json b/doc/apipie_examples.json index e14456d96..285fa49e3 100644 --- a/doc/apipie_examples.json +++ b/doc/apipie_examples.json @@ -45,6 +45,8 @@ "updated_at": "2008-09-01T08:05:00.000Z", "archived": false, "mandataire_social": false, + "state": "updated", + "simplified_state": "En construction", "entreprise": { "siren": "440117620", "capital_social": 537100000, @@ -174,4 +176,4 @@ "recorded": true } ] -} \ No newline at end of file +} diff --git a/spec/controllers/api/v1/dossiers_controller_spec.rb b/spec/controllers/api/v1/dossiers_controller_spec.rb index 463a644c1..67a4688f5 100644 --- a/spec/controllers/api/v1/dossiers_controller_spec.rb +++ b/spec/controllers/api/v1/dossiers_controller_spec.rb @@ -115,7 +115,7 @@ describe API::V1::DossiersController do let!(:dossier) { Timecop.freeze(date_creation) { create(:dossier, :with_entreprise, procedure: procedure) } } let(:dossier_id) { dossier.id } let(:body) { JSON.parse(retour.body, symbolize_names: true) } - let(:field_list) { [:id, :created_at, :updated_at, :archived, :mandataire_social, :entreprise, :etablissement, :cerfa, :types_de_piece_justificative, :pieces_justificatives, :champs, :champs_private, :commentaires, :state] } + let(:field_list) { [:id, :created_at, :updated_at, :archived, :mandataire_social, :entreprise, :etablissement, :cerfa, :types_de_piece_justificative, :pieces_justificatives, :champs, :champs_private, :commentaires, :state, :simplified_state] } subject { body[:dossier] } it 'return REST code 200', :show_in_doc do