From d5911071f8cd5f06009690984cc070c23f787c04 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Tue, 4 Jun 2019 15:28:23 +0200 Subject: [PATCH] Return dossiers on api with stable order --- app/controllers/api/v1/dossiers_controller.rb | 2 +- app/models/dossier.rb | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app/controllers/api/v1/dossiers_controller.rb b/app/controllers/api/v1/dossiers_controller.rb index 40cbcc1fa..5eb8eaadd 100644 --- a/app/controllers/api/v1/dossiers_controller.rb +++ b/app/controllers/api/v1/dossiers_controller.rb @@ -45,7 +45,7 @@ class API::V1::DossiersController < APIController render json: {}, status: :unauthorized end - @dossiers = @procedure.dossiers.state_not_brouillon + @dossiers = @procedure.dossiers.state_not_brouillon.order_for_api rescue ActiveRecord::RecordNotFound render json: {}, status: :not_found diff --git a/app/models/dossier.rb b/app/models/dossier.rb index abcfd983f..0bcb8669a 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -51,6 +51,7 @@ class Dossier < ApplicationRecord scope :not_archived, -> { where(archived: false) } 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 :en_construction, -> { not_archived.state_en_construction }