Commit d6d84661 authored by Emmanuel Raviart's avatar Emmanuel Raviart

Upgrade to Rocket 0.4 & Juniper 0.11.

parent 7c9d3d92
Pipeline #99497 failed with stage
in 32 minutes and 28 seconds
This diff is collapsed.
......@@ -5,8 +5,8 @@ authors = ["Emmanuel Raviart <emmanuel@raviart.com>"]
[dependencies]
chrono = { version = "0.4", features = ["serde"] }
juniper = "0.10"
juniper_codegen = "0.10"
juniper = "0.11"
juniper_codegen = "0.11"
lazy_static = "1"
regex = "1"
serde = "1"
......
......@@ -4,7 +4,7 @@ use acteurs::Acteur;
use commun::{CycleDeVie, EmptyChoice, Ident, ListePays, Uid, XmlNamespace};
use contexts::Context;
use organes::Organe;
use points_odj::PointsOdj;
use points_odj::{PointOdj, PointsOdj};
use serde_utils::{map_to_vec, str_to_bool, str_to_option_bool, str_to_vec};
#[derive(Clone, Debug, Deserialize)]
......@@ -114,7 +114,7 @@ pub struct LieuReunion {
pub libelle_long: Option<String>,
}
#[derive(Clone, Debug, Deserialize, GraphQLObject)]
#[derive(Clone, Debug, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct Odj {
#[serde(rename = "convocationODJ")]
......@@ -125,6 +125,37 @@ pub struct Odj {
pub resume_odj: Option<UnstructuredPointsOdj>,
}
graphql_object!(Odj: Context |&self| {
field convocation_odj() -> Vec<&str> {
match self.convocation_odj {
None => vec![],
Some(ref convocation_odj) => convocation_odj.items
.iter()
.map(|s| s.as_str())
.collect()
}
}
field points_odj() -> Vec<&PointOdj> {
match self.points_odj {
None => vec![],
Some(ref points_odj) => points_odj.points_odj
.iter()
.collect()
}
}
field resume_odj() -> Vec<&str> {
match self.resume_odj {
None => vec![],
Some(ref resume_odj) => resume_odj.items
.iter()
.map(|s| s.as_str())
.collect()
}
}
});
#[derive(Clone, Debug, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct OrganeDemandeur {
......@@ -318,7 +349,7 @@ pub struct Reunions {
pub reunions: Vec<Reunion>,
}
#[derive(Clone, Debug, Deserialize, GraphQLObject)]
#[derive(Clone, Debug, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct UnstructuredPointsOdj {
#[serde(deserialize_with = "str_to_vec", rename = "item")]
......
......@@ -30,21 +30,25 @@ pub struct CycleDeVie {
pub etat: String,
}
#[derive(Clone, Debug, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct EmptyChoice {}
// #[derive(Clone, Debug, Deserialize)]
// #[serde(deny_unknown_fields)]
// pub struct EmptyChoice {}
// graphql_scalar!(EmptyChoice {
// resolve(&self) -> juniper::Value {
// juniper::Value::Null
// }
graphql_scalar!(EmptyChoice {
description: "A value that never occurs, always null"
// from_input_value(v: &InputValue) -> Option<EmptyChoice> {
// None
// }
resolve(&self) -> juniper::Value {
juniper::Value::Null
}
// from_str<'a>(value: ScalarToken<'a>) -> juniper::ParseScalarResult<'a, juniper::DefaultScalarValue> {
// Err(juniper::parser::ParseError::UnexpectedToken(juniper::parser::Token::Scalar(value)))
// }
// });
from_input_value(_v: &InputValue) -> Option<EmptyChoice> {
None
}
});
pub type EmptyChoice = bool;
#[derive(Debug, Deserialize, GraphQLObject)]
#[serde(deny_unknown_fields)]
......
......@@ -263,7 +263,7 @@ graphql_union!(Mandat: Context |&self| {
// self.nomin_principale()
// }
// field organes() -> &Organes {
// field organes() -> &Vec<Organe> {
// self.organes()
// }
......
use commun::{EmptyChoice, ListePays};
use contexts::Context;
use types_organes::CodeTypeOrgane;
#[derive(Clone, Debug, Deserialize, GraphQLObject)]
#[derive(Clone, Debug, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct GroupePolitique {
chambre: Option<EmptyChoice>,
......@@ -26,6 +27,72 @@ pub struct GroupePolitique {
pub vimode: Vimode,
}
graphql_object!(GroupePolitique: Context |&self| {
field code_type() -> &CodeTypeOrgane {
&self.code_type
}
field legislature() -> Option<&str> {
// TODO: Convert to u8.
match &self.legislature {
None => None,
Some(ref s) => Some(s.as_str()),
}
}
field libelle() -> &str {
&self.libelle
}
field libelle_abrege() -> &str {
&self.libelle_abrege
}
field libelle_abrev() -> &str {
&self.libelle_abrev
}
field libelle_edition() -> Option<&str> {
match &self.libelle_edition {
None => None,
Some(ref s) => Some(s.as_str()),
}
}
field organe_parent() -> Option<&str> {
match &self.organe_parent {
None => None,
Some(ref s) => Some(s.as_str()),
}
}
field position_politique() -> Option<&str> {
match &self.position_politique {
None => None,
Some(ref s) => Some(s.as_str()),
}
}
field regime() -> Option<&str> {
match &self.regime {
None => None,
Some(ref s) => Some(s.as_str()),
}
}
field secretariat() -> &Secretariat {
&self.secretariat
}
field uid() -> &str {
&self.uid
}
field vimode() -> &Vimode {
&self.vimode
}
});
#[derive(Clone, Debug, Deserialize)]
#[serde(tag = "@xsi:type")]
pub enum Organe {
......@@ -187,8 +254,8 @@ impl Organe {
}
// Using graphql_union because instance_resolvers of graphql_interface does not work with Juniper 0.9.2.
// graphql_interface!(Organe: () |&self| {
graphql_union!(Organe: () |&self| {
// graphql_interface!(Organe: Context |&self| {
graphql_union!(Organe: Context |&self| {
// field code_type() -> CodeTypeOrgane {
// self.code_type()
// }
......@@ -245,7 +312,7 @@ graphql_union!(Organe: () |&self| {
}
});
#[derive(Clone, Debug, Deserialize, GraphQLObject)]
#[derive(Clone, Debug, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct OrganeExterne {
#[serde(rename = "codeType")]
......@@ -264,7 +331,47 @@ pub struct OrganeExterne {
pub vimode: Vimode,
}
#[derive(Clone, Debug, Deserialize, GraphQLObject)]
graphql_object!(OrganeExterne: Context |&self| {
field code_type() -> &CodeTypeOrgane {
&self.code_type
}
field libelle() -> &str {
&self.libelle
}
field libelle_abrege() -> &str {
&self.libelle_abrege
}
field libelle_abrev() -> &str {
&self.libelle_abrev
}
field libelle_edition() -> Option<&str> {
match &self.libelle_edition {
None => None,
Some(ref s) => Some(s.as_str()),
}
}
field organe_parent() -> Option<&str> {
match &self.organe_parent {
None => None,
Some(ref s) => Some(s.as_str()),
}
}
field uid() -> &str {
&self.uid
}
field vimode() -> &Vimode {
&self.vimode
}
});
#[derive(Clone, Debug, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct OrganeExtraParlementaire {
chambre: Option<EmptyChoice>,
......@@ -292,7 +399,75 @@ pub struct OrganeExtraParlementaire {
pub vimode: Vimode,
}
#[derive(Clone, Debug, Deserialize, GraphQLObject)]
graphql_object!(OrganeExtraParlementaire: Context |&self| {
field code_type() -> &CodeTypeOrgane {
&self.code_type
}
field libelle() -> &str {
&self.libelle
}
field libelle_abrege() -> &str {
&self.libelle_abrege
}
field libelle_abrev() -> &str {
&self.libelle_abrev
}
field libelle_edition() -> Option<&str> {
match &self.libelle_edition {
None => None,
Some(ref s) => Some(s.as_str()),
}
}
field nombre_reunions_annuelles() -> Option<&str> {
match &self.nombre_reunions_annuelles {
None => None,
Some(ref s) => Some(s.as_str()),
}
}
field organe_parent() -> Option<&str> {
match &self.organe_parent {
None => None,
Some(ref s) => Some(s.as_str()),
}
}
field regime() -> Option<&str> {
match &self.regime {
None => None,
Some(ref s) => Some(s.as_str()),
}
}
field regime_juridique() -> Option<&str> {
match &self.regime_juridique {
None => None,
Some(ref s) => Some(s.as_str()),
}
}
field site_internet() -> Option<&str> {
match &self.site_internet {
None => None,
Some(ref s) => Some(s.as_str()),
}
}
field uid() -> &str {
&self.uid
}
field vimode() -> &Vimode {
&self.vimode
}
});
#[derive(Clone, Debug, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct OrganeParlementaire {
chambre: Option<EmptyChoice>,
......@@ -315,7 +490,66 @@ pub struct OrganeParlementaire {
pub vimode: Vimode,
}
#[derive(Clone, Debug, Deserialize, GraphQLObject)]
graphql_object!(OrganeParlementaire: Context |&self| {
field code_type() -> &CodeTypeOrgane {
&self.code_type
}
field legislature() -> Option<&str> {
// TODO: Convert to u8.
match &self.legislature {
None => None,
Some(ref s) => Some(s.as_str()),
}
}
field libelle() -> &str {
&self.libelle
}
field libelle_abrege() -> &str {
&self.libelle_abrege
}
field libelle_abrev() -> &str {
&self.libelle_abrev
}
field libelle_edition() -> Option<&str> {
match &self.libelle_edition {
None => None,
Some(ref s) => Some(s.as_str()),
}
}
field organe_parent() -> Option<&str> {
match &self.organe_parent {
None => None,
Some(ref s) => Some(s.as_str()),
}
}
field regime() -> Option<&str> {
match &self.regime {
None => None,
Some(ref s) => Some(s.as_str()),
}
}
field secretariat() -> &Secretariat {
&self.secretariat
}
field uid() -> &str {
&self.uid
}
field vimode() -> &Vimode {
&self.vimode
}
});
#[derive(Clone, Debug, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct OrganeParlementaireInternational {
chambre: Option<EmptyChoice>,
......@@ -340,7 +574,70 @@ pub struct OrganeParlementaireInternational {
pub vimode: Vimode,
}
#[derive(Debug, Deserialize, GraphQLObject)]
graphql_object!(OrganeParlementaireInternational: Context |&self| {
field code_type() -> &CodeTypeOrgane {
&self.code_type
}
field legislature() -> Option<&str> {
// TODO: Convert to u8.
match &self.legislature {
None => None,
Some(ref s) => Some(s.as_str()),
}
}
field libelle() -> &str {
&self.libelle
}
field libelle_abrege() -> &str {
&self.libelle_abrege
}
field libelle_abrev() -> &str {
&self.libelle_abrev
}
field libelle_edition() -> Option<&str> {
match &self.libelle_edition {
None => None,
Some(ref s) => Some(s.as_str()),
}
}
field liste_pays() -> &Option<ListePays> {
&self.liste_pays
}
field organe_parent() -> Option<&str> {
match &self.organe_parent {
None => None,
Some(ref s) => Some(s.as_str()),
}
}
field regime() -> Option<&str> {
match &self.regime {
None => None,
Some(ref s) => Some(s.as_str()),
}
}
field secretariat() -> &Secretariat {
&self.secretariat
}
field uid() -> &str {
&self.uid
}
field vimode() -> &Vimode {
&self.vimode
}
});
#[derive(Debug, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct Organes {
#[serde(rename = "organe")]
......
use commun::{CycleDeVie, EmptyChoice};
use contexts::Context;
use serde_utils::{map_to_vec, str_to_bool, str_to_vec};
#[derive(Clone, Debug, Deserialize, GraphQLObject)]
......@@ -8,7 +9,7 @@ pub struct DossiersLegislatifsRefs {
pub dossiers_refs: Vec<String>,
}
#[derive(Clone, Debug, Deserialize, GraphQLObject)]
#[derive(Clone, Debug, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct PodjReunion {
#[serde(deserialize_with = "str_to_bool", rename = "comiteSecret")]
......@@ -28,7 +29,40 @@ pub struct PodjReunion {
pub uid: String,
}
#[derive(Clone, Debug, Deserialize, GraphQLObject)]
graphql_object!(PodjReunion: Context |&self| {
field comite_secret() -> bool {
self.comite_secret
}
field cycle_de_vie() -> &CycleDeVie {
&self.cycle_de_vie
}
field dossiers_legislatifs_refs() -> &Option<DossiersLegislatifsRefs> {
&self.dossiers_legislatifs_refs
}
field objet() -> &str {
&self.objet
}
field procedure() -> Option<&str> {
match &self.procedure {
None => None,
Some(ref s) => Some(s.as_str()),
}
}
field type_point_odj() -> &str {
&self.type_point_odj
}
field uid() -> &str {
&self.uid
}
});
#[derive(Clone, Debug, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct PodjSeanceConfPres {
#[serde(deserialize_with = "str_to_bool", rename = "comiteSecret")]
......@@ -56,6 +90,50 @@ pub struct PodjSeanceConfPres {
pub uid: String,
}
graphql_object!(PodjSeanceConfPres: Context |&self| {
field comite_secret() -> bool {
self.comite_secret
}
field cycle_de_vie() -> &CycleDeVie {
&self.cycle_de_vie
}
field date_conf_pres() -> Option<&str> {
match &self.date_conf_pres {
None => None,
Some(ref s) => Some(s.as_str()),
}
}
field dossiers_legislatifs_refs() -> &Option<DossiersLegislatifsRefs> {
&self.dossiers_legislatifs_refs
}
field nature_travaux_odj() -> &str {
&self.nature_travaux_odj
}
field objet() -> &str {
&self.objet
}
field procedure() -> Option<&str> {
match &self.procedure {
None => None,
Some(ref s) => Some(s.as_str()),
}
}
field type_point_odj() -> &str {
&self.type_point_odj
}
field uid() -> &str {
&self.uid
}
});
#[derive(Clone, Debug, Deserialize)]
#[serde(tag = "@xsi:type")]
pub enum PointOdj {
......@@ -141,8 +219,8 @@ impl PointOdj {
}
// Using graphql_union because instance_resolvers of graphql_interface does not work with Juniper 0.9.2.
// graphql_interface!(PointOdj: () |&self| {
graphql_union!(PointOdj: () |&self| {
// graphql_interface!(PointOdj: Context |&self| {
graphql_union!(PointOdj: Context |&self| {
// field comite_secret() -> bool {
// self.comite_secret()
// }
......@@ -183,7 +261,7 @@ graphql_union!(PointOdj: () |&self| {
}
});
#[derive(Clone, Debug, Deserialize, GraphQLObject)]
#[derive(Clone, Debug, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct PointsOdj {
#[serde(deserialize_with = "map_to_vec", rename = "pointODJ")]
......
use commun::{EmptyChoice, XmlNamespace};
use contexts::Context;
use serde_utils::{map_to_vec, str_to_option_bool};
#[derive(Clone, Copy, Debug, Deserialize, GraphQLEnum)]
......@@ -35,7 +36,7 @@ pub struct DecompteMiseAuPoint {
pours: Option<DecompteVotants>,
}
graphql_object!(DecompteMiseAuPoint: () |&self| {
graphql_object!(DecompteMiseAuPoint: Context |&self| {
field abstentions() -> &Option<DecompteVotants> {
&self.abstentions.1
}
......@@ -157,7 +158,7 @@ pub struct OrganeVote {
organe: Organe,
}
#[derive(Debug, Deserialize, GraphQLObject)]
#[derive(Debug, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct Scrutin {
#[serde(rename = "dateScrutin")]
......@@ -192,6 +193,68 @@ pub struct Scrutin {
xml_xsi: Option<XmlNamespace>,
}
graphql_object!(Scrutin: Context |&self| {
field date_scrutin() -> &str {
&self.date_scrutin
}
field demandeur() -> &Demandeur {
&self.demandeur
}
field legislature() -> &str {
&self.legislature
}
field mise_au_point() -> &Option<DecompteMiseAuPoint> {
&self.mise_au_point
}
field mode_publication_des_votes() -> &ModePublicationDesVotes {
&self.mode_publication_des_votes
}
field organe_ref() -> &str {
&self.organe_ref
}
field quantieme_jour_seance() -> &str {
&self.quantieme_jour_seance
}
field seance_ref() -> &str {
&self.seance_ref
}
field session_ref() -> &str {
&self.session_ref
}
field sort() -> &Sort {
&self.sort
}
field synthese_vote() -> &SyntheseVote {
&self.synthese_vote
}
field titre() -> &str {
&self.titre
}
field type_vote() -> &TypeVote {
&self.type_vote
}
field uid() -> &str {
&self.uid
}
field ventilation_votes() -> &OrganeVote {
&self.ventilation_votes
}
});
#[derive(Debug, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct Scrutins {
......
......@@ -6,15 +6,14 @@ authors = ["Emmanuel Raviart <emmanuel@raviart.com>"]
[dependencies]
chrono = { version = "0.4", features = ["serde"] }
clap = "2.32"
env_logger = "0.5"
env_logger = "0.6"
futures = "0.1"
itertools = "0.7"
juniper = "0.10"
juniper_codegen = "0.10"
juniper_rocket = "0.1"
rocket = "0.3"
rocket_codegen = "0.3"
rocket_cors = "0.3"
itertools = "0.8"
juniper = "0.11"
juniper_codegen = "0.11"
juniper_rocket = "0.2"
rocket = "0.4"
rocket_cors = "0.4"
serde = "1"
serde_derive = "1"
serde_json = "1"
......
......@@ -9,6 +9,7 @@ extern crate itertools;
#[macro_use]
extern crate juniper;
extern crate juniper_rocket;
#[macro_use]
extern crate rocket;
extern crate rocket_cors;
extern crate serde;
......@@ -49,8 +50,8 @@ graphql_object!(Query: Context |&self| {
field agenda(&executor, acteur_uid: Option<String>, date_debut: Option<String>, date_fin: Option<String>) -> FieldResult<Vec<&Reunion>> {
let context = executor.context();
let mut date_debut = date_debut.map(|date_debut| DateTime::parse_from_rfc3339(&date_debut).expect(&format!("Invalid date & time: {}", date_debut)).date());
let mut date_fin = date_fin.map(|date_fin| DateTime::parse_from_rfc3339(&date_fin).expect(&format!("Invalid date & time: {}", date_fin)).date());
let date_debut = date_debut.map(|date_debut|