Commit 6ed19477 authored by Emmanuel Raviart's avatar Emmanuel Raviart

Improve some fields of "actes". Add GraphQL endpoints.

parent 4be3a651
Pipeline #100770 passed with stage
in 2 minutes and 17 seconds
This diff is collapsed.
......@@ -5,7 +5,7 @@ use amendements::{self, Amendement, TexteLeg};
use dossiers_legislatifs::{self, DossierParlementaire};
use juniper;
use organes::Organe;
use scrutins;
use scrutins::{self, Scrutin};
use std::collections::HashMap;
use std::mem;
use textes_legislatifs::Document;
......@@ -22,8 +22,10 @@ pub struct Context {
pub dossier_parlementaire_by_uid: HashMap<String, *const DossierParlementaire>,
pub dossiers_legislatifs_wrappers: Vec<dossiers_legislatifs::ExportJsonWrapper>,
pub organe_by_uid: HashMap<String, *const Organe>,
pub reunion_by_uid: HashMap<String, *const Reunion>,
pub reunions_by_date: HashMap<String, Vec<*const Reunion>>,
pub reunions_by_dossier_uid: HashMap<String, Vec<*const Reunion>>,
pub scrutin_by_uid: HashMap<String, *const Scrutin>,
pub scrutins_wrappers: Vec<scrutins::ScrutinsJsonWrapper>,
pub texte_leg_by_uid: HashMap<String, *const TexteLeg>,
}
......@@ -85,6 +87,12 @@ impl Context {
.map(|organe| unsafe { mem::transmute::<*const Organe, &Organe>(*organe) })
}
pub fn get_reunion_at_uid(&self, uid: &str) -> Option<&Reunion> {
self.reunion_by_uid
.get(&uid.to_string())
.map(|reunion| unsafe { mem::transmute::<*const Reunion, &Reunion>(*reunion) })
}
pub fn get_reunions_at_date(&self, date: &str) -> Option<&Vec<&Reunion>> {
self.reunions_by_date
.get(&date.to_string())
......@@ -101,6 +109,12 @@ impl Context {
})
}
pub fn get_scrutin_at_uid(&self, uid: &str) -> Option<&Scrutin> {
self.scrutin_by_uid
.get(&uid.to_string())
.map(|scrutin| unsafe { mem::transmute::<*const Scrutin, &Scrutin>(*scrutin) })
}
pub fn get_texte_leg_at_uid(&self, uid: &str) -> Option<&TexteLeg> {
self.texte_leg_by_uid
.get(&uid.to_string())
......
......@@ -240,6 +240,7 @@ pub fn load(
}
}
// Index recursive structures to allow them to be flattened for GraphQL transmission.
for mut wrapper in &mut dossiers_legislatifs_wrappers {
for mut document in &mut wrapper.export.textes_legislatifs.documents {
let mut index: i32 = 0;
......@@ -332,6 +333,13 @@ pub fn load(
}
}
let mut reunion_by_uid: HashMap<String, *const Reunion> = HashMap::new();
for wrapper in &agendas_wrappers {
for reunion in &wrapper.reunions.reunions {
reunion_by_uid.insert(reunion.uid.clone(), reunion);
}
}
let mut reunions_by_date: HashMap<String, Vec<*const Reunion>> = HashMap::new();
for wrapper in &agendas_wrappers {
for reunion in &wrapper.reunions.reunions {
......@@ -364,6 +372,13 @@ pub fn load(
}
}
let mut scrutin_by_uid: HashMap<String, *const Scrutin> = HashMap::new();
for wrapper in &scrutins_wrappers {
for scrutin in &wrapper.scrutins.scrutins {
scrutin_by_uid.insert(scrutin.uid.clone(), scrutin);
}
}
Context {
acteur_by_uid,
acteurs_et_organes_wrappers,
......@@ -376,8 +391,10 @@ pub fn load(
dossier_parlementaire_by_uid,
dossiers_legislatifs_wrappers,
organe_by_uid,
reunion_by_uid,
reunions_by_date,
reunions_by_dossier_uid,
scrutin_by_uid,
scrutins_wrappers,
texte_leg_by_uid,
}
......
......@@ -164,33 +164,33 @@ pub struct Scrutin {
#[serde(rename = "dateScrutin")]
// TODO: Date<FixedOffset> type is not able to deserialize dates.
pub date_scrutin: String,
demandeur: Demandeur,
legislature: String,
pub demandeur: Demandeur,
pub legislature: String,
#[serde(rename = "miseAuPoint")]
mise_au_point: Option<DecompteMiseAuPoint>,
pub mise_au_point: Option<DecompteMiseAuPoint>,
#[serde(rename = "modePublicationDesVotes")]
mode_publication_des_votes: ModePublicationDesVotes,
numero: String,
objet: Objet,
pub mode_publication_des_votes: ModePublicationDesVotes,
pub numero: String,
pub objet: Objet,
#[serde(rename = "organeRef")]
organe_ref: String,
pub organe_ref: String,
#[serde(rename = "quantiemeJourSeance")]
quantieme_jour_seance: String,
pub quantieme_jour_seance: String,
#[serde(rename = "seanceRef")]
seance_ref: String,
pub seance_ref: String,
#[serde(rename = "sessionRef")]
session_ref: String,
sort: Sort,
pub session_ref: String,
pub sort: Sort,
#[serde(rename = "syntheseVote")]
synthese_vote: SyntheseVote,
titre: String,
pub synthese_vote: SyntheseVote,
pub titre: String,
#[serde(rename = "typeVote")]
type_vote: TypeVote,
uid: String,
pub type_vote: TypeVote,
pub uid: String,
#[serde(rename = "ventilationVotes")]
ventilation_votes: OrganeVote,
pub ventilation_votes: OrganeVote,
#[serde(rename = "@xmlns:xsi")]
xml_xsi: Option<XmlNamespace>,
pub xml_xsi: Option<XmlNamespace>,
}
graphql_object!(Scrutin: Context |&self| {
......
......@@ -464,6 +464,10 @@ graphql_object!(Query: Context |&self| {
Ok(15)
}
field organe(&executor, uid: String) -> FieldResult<Option<&Organe>> {
Ok(executor.context().get_organe_at_uid(&uid))
}
field organes(&executor) -> FieldResult<Vec<&Organe>> {
let mut organes: Vec<&Organe> = Vec::new();
for wrapper in &executor.context().acteurs_et_organes_wrappers {
......@@ -474,6 +478,14 @@ graphql_object!(Query: Context |&self| {
Ok(organes)
}
field reunion(&executor, uid: String) -> FieldResult<Option<&Reunion>> {
Ok(executor.context().get_reunion_at_uid(&uid))
}
field scrutin(&executor, uid: String) -> FieldResult<Option<&Scrutin>> {
Ok(executor.context().get_scrutin_at_uid(&uid))
}
field scrutins(&executor) -> FieldResult<Vec<&Scrutin>> {
let mut scrutins: Vec<&Scrutin> = Vec::new();
for wrapper in &executor.context().scrutins_wrappers {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment