Return dossiers on api with stable order (#3921)

API : l'ordre des dossiers renvoyés dans les résultats paginés est maintenant stable
This commit is contained in:
Pierre de La Morinerie 2019-06-04 15:44:32 +02:00 committed by GitHub
commit d050b9dc07
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 2 additions and 1 deletions

View file

@ -45,7 +45,7 @@ class API::V1::DossiersController < APIController
render json: {}, status: :unauthorized render json: {}, status: :unauthorized
end end
@dossiers = @procedure.dossiers.state_not_brouillon @dossiers = @procedure.dossiers.state_not_brouillon.order_for_api
rescue ActiveRecord::RecordNotFound rescue ActiveRecord::RecordNotFound
render json: {}, status: :not_found render json: {}, status: :not_found

View file

@ -51,6 +51,7 @@ class Dossier < ApplicationRecord
scope :not_archived, -> { where(archived: false) } scope :not_archived, -> { where(archived: false) }
scope :order_by_updated_at, -> (order = :desc) { order(updated_at: order) } scope :order_by_updated_at, -> (order = :desc) { order(updated_at: order) }
scope :order_for_api, -> (order = :asc) { order(en_construction_at: order, created_at: order, id: order) }
scope :all_state, -> { not_archived.state_not_brouillon } scope :all_state, -> { not_archived.state_not_brouillon }
scope :en_construction, -> { not_archived.state_en_construction } scope :en_construction, -> { not_archived.state_en_construction }