Commit 9cca6150 authored by Emmanuel Raviart's avatar Emmanuel Raviart

Add GraphQL function `amendements_texte_legislatif`.

parent e889af06
Pipeline #99350 failed with stage
in 34 minutes and 29 seconds
......@@ -1580,16 +1580,16 @@ graphql_object!(DiscussionSeancePublique: Context |&self| {
&self.libelle_acte
}
field odj_ref() -> &str {
&self.odj_ref
field odj_ref() -> Option<&str> {
Some(self.odj_ref.as_str())
}
field organe_ref() -> &str {
&self.organe_ref
}
field reunion_ref() -> &str {
&self.reunion_ref
field reunion_ref() -> Option<&str> {
Some(self.reunion_ref.as_str())
}
field uid() -> &str {
......
use commun::{EmptyChoice, XmlNamespace};
use contexts::Context;
use serde_utils::{map_to_vec, str_to_bool, str_to_option_bool, str_to_vec};
use textes_legislatifs::{Document};
#[derive(Debug, Deserialize, GraphQLObject)]
#[serde(deny_unknown_fields)]
......@@ -100,7 +102,7 @@ pub struct Amendements {
pub verbatim: Option<bool>,
}
#[derive(Debug, Deserialize, GraphQLObject)]
#[derive(Debug, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct AmendementsJsonWrapper {
#[serde(rename = "textesEtAmendements")]
......@@ -355,14 +357,20 @@ pub struct StatutRepresentation {
pub verbatim: bool,
}
#[derive(Debug, Deserialize, GraphQLObject)]
#[derive(Debug, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct TextesEtAmendements {
#[serde(rename = "texteleg")]
pub texteleg: Vec<TexteLeg>,
pub texte_leg: Vec<TexteLeg>,
}
#[derive(Debug, Deserialize, GraphQLObject)]
graphql_object!(TextesEtAmendements: Context |&self| {
field texte_leg() -> &Vec<TexteLeg> {
&self.texte_leg
}
});
#[derive(Debug, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct TexteLeg {
#[serde(rename = "@xmlns:xsi")]
......@@ -373,6 +381,29 @@ pub struct TexteLeg {
pub ref_texte_legislatif: Option<String>,
}
graphql_object!(TexteLeg: Context |&self| {
field amendements() -> &Option<Amendements> {
&self.amendements
}
field ref_texte_legislatif() -> Option<&str> {
match &self.ref_texte_legislatif {
None => None,
Some(ref s) => Some(s.as_str()),
}
}
field texte_legislatif(&executor) -> Option<&Document> {
match &self.ref_texte_legislatif {
None => None,
Some(ref ref_texte_legislatif) => {
let context = &executor.context();
context.get_document_at_uid(ref_texte_legislatif)
},
}
}
});
#[derive(Debug, Deserialize, GraphQLObject)]
#[serde(deny_unknown_fields)]
pub struct TotalMontants {
......@@ -387,8 +418,8 @@ pub struct TotalMontants {
#[derive(Debug, Deserialize, GraphQLObject)]
#[serde(deny_unknown_fields)]
pub struct TypeMime {
#[serde(rename = "type")]
mime_type: Option<String>,
#[serde(rename = "subType")]
pub sub_type: Option<String>,
#[serde(rename = "type")]
mimetype: Option<String>,
}
use acteurs::Acteur;
use acteurs_et_organes;
use agendas::{self, Reunion};
use amendements::{self, Amendement};
use amendements::{self, Amendement, TexteLeg};
use dossiers_legislatifs::{self, DossierParlementaire};
use juniper;
use organes::Organe;
......@@ -25,6 +25,7 @@ pub struct Context {
pub reunions_by_date: HashMap<String, Vec<*const Reunion>>,
pub reunions_by_dossier_uid: HashMap<String, Vec<*const Reunion>>,
pub scrutins_wrappers: Vec<scrutins::ScrutinsJsonWrapper>,
pub texte_leg_by_uid: HashMap<String, *const TexteLeg>,
}
impl Context {
......@@ -101,6 +102,14 @@ impl Context {
mem::transmute::<&Vec<*const Reunion>, &Vec<&Reunion>>(reunions)
})
}
pub fn get_texte_leg_at_uid(&self, uid: &str) -> Option<&TexteLeg> {
self.texte_leg_by_uid
.get(&uid.to_string())
.map(|texte_leg| unsafe {
mem::transmute::<*const TexteLeg, &TexteLeg>(*texte_leg)
})
}
}
unsafe impl Send for Context {}
......
......@@ -34,7 +34,7 @@ mod types_organes;
pub use acteurs::Acteur;
pub use agendas::Reunion;
pub use amendements::{Amendement, TextesEtAmendements};
pub use amendements::{Amendement, TexteLeg, TextesEtAmendements};
use config::{Config, Verbosity};
pub use contexts::Context;
pub use dossiers_legislatifs::DossierParlementaire;
......@@ -254,12 +254,19 @@ pub fn load(
}
let mut amendement_by_uid: HashMap<String, *const Amendement> = HashMap::new();
let mut texte_leg_by_uid: HashMap<String, *const TexteLeg> = HashMap::new();
for wrapper in &amendements_wrappers {
match &wrapper.textes_et_amendements {
None => (),
Some(ref textes_et_amendements) => {
for texteleg in &textes_et_amendements.texteleg {
match &texteleg.amendements {
for texte_leg in &textes_et_amendements.texte_leg {
match &texte_leg.ref_texte_legislatif {
None => (),
Some(ref ref_texte_legislatif) => {
texte_leg_by_uid.insert(ref_texte_legislatif.clone(), texte_leg);
}
}
match &texte_leg.amendements {
None => (),
Some(ref amendements) => {
for amendement in &amendements.amendements {
......@@ -371,5 +378,6 @@ pub fn load(
reunions_by_date,
reunions_by_dossier_uid,
scrutins_wrappers,
texte_leg_by_uid,
}
}
......@@ -21,7 +21,7 @@ use clap::{App, Arg};
use config::Verbosity;
use data::{
Acteur, Amendement, CodeTypeOrgane, Context, Document, DossierParlementaire, FonctionOrgane,
Mandat, Organe, Reunion, Scrutin, TextesEtAmendements, ALL_DATASETS, FONCTIONS_ORGANES,
Mandat, Organe, Reunion, Scrutin, TexteLeg, TextesEtAmendements, ALL_DATASETS, FONCTIONS_ORGANES,
};
use juniper::{EmptyMutation, FieldResult, RootNode};
use rocket::http::Method;
......@@ -220,8 +220,8 @@ graphql_object!(Query: Context |&self| {
let timestamp_until_ref = NaiveDateTime::timestamp(&tmp_until_ref.and_hms(00,00,00));
for wrapper in &executor.context().amendements_wrappers{
for texteleg in &wrapper.textes_et_amendements{
for txtleg in &texteleg.texteleg{
for texte_leg in &wrapper.textes_et_amendements{
for txtleg in &texte_leg.texte_leg{
for amds in &txtleg.amendements{
for amd in &amds.amendements{
match &amd.date_depot {
......@@ -242,8 +242,8 @@ graphql_object!(Query: Context |&self| {
},
None => {
for wrapper in &executor.context().amendements_wrappers{
for texteleg in &wrapper.textes_et_amendements{
for txtleg in &texteleg.texteleg{
for texte_leg in &wrapper.textes_et_amendements{
for txtleg in &texte_leg.texte_leg{
for amds in &txtleg.amendements{
for amd in &amds.amendements{
match &amd.date_depot {
......@@ -272,8 +272,8 @@ graphql_object!(Query: Context |&self| {
let timestamp_until_ref = NaiveDateTime::timestamp(&tmp_until_ref.and_hms(00,00,00));
for wrapper in &executor.context().amendements_wrappers{
for texteleg in &wrapper.textes_et_amendements{
for txtleg in &texteleg.texteleg{
for texte_leg in &wrapper.textes_et_amendements{
for txtleg in &texte_leg.texte_leg{
for amds in &txtleg.amendements{
for amd in &amds.amendements{
match &amd.date_depot {
......@@ -294,8 +294,8 @@ graphql_object!(Query: Context |&self| {
},
None => {
for wrapper in &executor.context().amendements_wrappers{
for texteleg in &wrapper.textes_et_amendements{
for txtleg in &texteleg.texteleg{
for texte_leg in &wrapper.textes_et_amendements{
for txtleg in &texte_leg.texte_leg{
for amds in &txtleg.amendements{
for amd in &amds.amendements{
amendements.push(&amd);
......@@ -311,6 +311,13 @@ graphql_object!(Query: Context |&self| {
Ok(amendements)
}
field amendements_texte_legislatif(
&executor,
uid: String as "Identifiant du texte législatif recherché",
) -> FieldResult<Option<&TexteLeg>> as "Rechercher les amendements d'un texte législatif par son identifiant" {
Ok(executor.context().get_texte_leg_at_uid(&uid))
}
field deputes(&executor, date: Option<String>) -> FieldResult<Vec<&Acteur>> {
let date = match date {
None => None,
......@@ -472,8 +479,8 @@ graphql_object!(Query: Context |&self| {
field textesetamendements(&executor) -> FieldResult<Vec<&TextesEtAmendements>> {
let mut textes_et_amendements: Vec<&TextesEtAmendements> = Vec::new();
for wrapper in &executor.context().amendements_wrappers{
for texteleg in &wrapper.textes_et_amendements {
textes_et_amendements.push(&texteleg);
for texte_leg in &wrapper.textes_et_amendements {
textes_et_amendements.push(&texte_leg);
}
}
Ok(textes_et_amendements)
......
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