demarches-normaliennes/app/controllers/api/v1/dossiers_controller.rb

47 lines
1.8 KiB
Ruby
Raw Normal View History

2016-01-20 15:48:46 +01:00
class API::V1::DossiersController < APIController
api :GET, '/procedures/:procedure_id/dossiers/', 'Liste de tous les dossiers d\'une procédure'
param :procedure_id, Integer, desc: "L'identifiant de la procédure", required: true
2016-02-26 14:16:17 +01:00
param :token, String, desc: "Token administrateur", required: true
error code: 401, desc: "Non authorisé"
error code: 404, desc: "Procédure inconnue"
2016-01-20 15:48:46 +01:00
def index
procedure = current_administrateur.procedures.find(params[:procedure_id])
2017-12-28 19:31:28 +01:00
dossiers = procedure.dossiers.state_not_brouillon.page(params[:page]).per(per_page)
2016-11-15 09:54:17 +01:00
render json: { dossiers: dossiers.map{ |dossier| DossiersSerializer.new(dossier) }, pagination: pagination(dossiers) }, status: 200
2017-04-14 17:05:38 +02:00
rescue ActiveRecord::RecordNotFound
2016-01-20 15:48:46 +01:00
render json: {}, status: 404
end
api :GET, '/procedures/:procedure_id/dossiers/:id', 'Informations du dossier d\'une procédure'
param :procedure_id, Integer, desc: "L'identifiant de la procédure", required: true
2016-02-26 14:16:17 +01:00
param :dossier_id, Integer, desc: "L'identifiant du dossier", required: true
param :token, String, desc: "Token administrateur", required: true
error code: 401, desc: "Non authorisé"
error code: 404, desc: "Procédure ou dossier inconnu"
def show
procedure = current_administrateur.procedures.find(params[:procedure_id])
dossier = procedure.dossiers.find(params[:id])
2016-11-15 09:54:17 +01:00
2016-02-19 16:59:18 +01:00
respond_to do |format|
format.json { render json: { dossier: DossierSerializer.new(dossier).as_json }, status: 200 }
2016-02-19 16:59:18 +01:00
end
2017-04-14 17:05:38 +02:00
rescue ActiveRecord::RecordNotFound
render json: {}, status: 404
end
def pagination(dossiers)
2016-01-20 15:48:46 +01:00
{
page: dossiers.current_page,
2017-12-28 19:31:28 +01:00
resultats_par_page: dossiers.limit_value,
nombre_de_page: dossiers.total_pages
2016-01-20 15:48:46 +01:00
}
end
2017-12-28 19:31:28 +01:00
def per_page # inherited value from will_paginate
12
end
2017-04-04 15:27:04 +02:00
end