2016-01-20 15:48:46 +01:00
|
|
|
class API::V1::DossiersController < APIController
|
2016-02-18 18:02:07 +01:00
|
|
|
|
2016-02-22 19:42:47 +01:00
|
|
|
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
|
2016-02-22 19:42:47 +01:00
|
|
|
error code: 401, desc: "Non authorisé"
|
|
|
|
error code: 404, desc: "Procédure inconnue"
|
|
|
|
|
|
|
|
description <<-EOS
|
|
|
|
Plop
|
|
|
|
EOS
|
|
|
|
|
|
|
|
meta champs: {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-01-20 15:48:46 +01:00
|
|
|
def index
|
|
|
|
procedure = current_administrateur.procedures.find(params[:procedure_id])
|
2016-02-02 18:11:44 +01:00
|
|
|
dossiers = procedure.dossiers.where.not(state: :draft).paginate(page: params[:page])
|
2016-01-21 11:41:24 +01:00
|
|
|
render json: dossiers, each_serializer: DossiersSerializer, meta: pagination(dossiers), meta_key: 'pagination', status: 200
|
2016-01-20 15:48:46 +01:00
|
|
|
rescue ActiveRecord::RecordNotFound => e
|
|
|
|
render json: {}, status: 404
|
|
|
|
end
|
|
|
|
|
2016-02-22 19:42:47 +01:00
|
|
|
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
|
2016-02-22 19:42:47 +01:00
|
|
|
error code: 401, desc: "Non authorisé"
|
|
|
|
error code: 404, desc: "Procédure ou dossier inconnu"
|
|
|
|
|
|
|
|
description <<-EOS
|
|
|
|
Plop
|
|
|
|
EOS
|
|
|
|
|
|
|
|
meta champs: {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-01-25 16:08:10 +01:00
|
|
|
def show
|
|
|
|
procedure = current_administrateur.procedures.find(params[:procedure_id])
|
|
|
|
dossier = procedure.dossiers.find(params[:id])
|
2016-02-19 16:59:18 +01:00
|
|
|
respond_to do |format|
|
|
|
|
format.json { render json: dossier, status: 200 }
|
|
|
|
format.csv { render csv: dossier, status: 200 }
|
|
|
|
end
|
2016-01-25 16:08:10 +01:00
|
|
|
rescue ActiveRecord::RecordNotFound => e
|
|
|
|
render json: {}, status: 404
|
|
|
|
end
|
|
|
|
|
|
|
|
def pagination(dossiers)
|
2016-01-20 15:48:46 +01:00
|
|
|
{
|
2016-02-02 18:11:44 +01:00
|
|
|
page: dossiers.current_page,
|
|
|
|
resultats_par_page: dossiers.per_page,
|
|
|
|
nombre_de_page: dossiers.total_pages
|
2016-01-20 15:48:46 +01:00
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|