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

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

parent 4be3a651
Pipeline #100770 passed with stage
in 2 minutes and 17 seconds
use acteurs::Acteur;
use agendas::Reunion;
use chrono::{Date, DateTime, FixedOffset};
use commun::{Codier, EmptyChoice, InfoJo, Rapporteur};
use contexts::Context;
use mandats::Mandat;
use organes::Organe;
use serde_utils::{map_to_vec, str_to_vec};
use scrutins::Scrutin;
use std::cmp;
use textes_legislatifs::Document;
......@@ -516,6 +518,11 @@ graphql_union!(ActeLegislatif: Context |&self| {
// self.libelle_acte()
// }
// field organe(&executor) -> Option<&Organe> {
// let context = &executor.context();
// context.get_organe_at_uid(&self.organe_ref())
// }
// field organe_ref() -> Option<&str> {
// self.organe_ref()
// }
......@@ -813,8 +820,13 @@ graphql_object!(ConclusionEtapeCc: Context |&self| {
&self.num_decision
}
field organe_ref() -> &str {
&self.organe_ref
field organe(&executor) -> Option<&Organe> {
let context = &executor.context();
context.get_organe_at_uid(&self.organe_ref)
}
field organe_ref() -> Option<&str> {
Some(self.organe_ref.as_str())
}
field statut_conclusion() -> &Codier {
......@@ -867,16 +879,34 @@ graphql_object!(CreationOrganeTemporaire: Context |&self| {
self.date_acte
}
field initiateurs() -> &Option<InitiateursCreationOrganeTemporaire> {
&self.initiateurs
field initiateurs(&executor) -> Option<&Organe> {
match &self.initiateurs {
None => None,
Some(ref initiateurs) => {
let context = &executor.context();
context.get_organe_at_uid(&initiateurs.organe_ref)
},
}
}
field initiateurs_ref() -> Option<&str> {
match &self.initiateurs {
None => None,
Some(ref initiateurs) => Some(initiateurs.organe_ref.as_str()),
}
}
field libelle_acte() -> &LibelleActe {
&self.libelle_acte
}
field organe_ref() -> &str {
&self.organe_ref
field organe(&executor) -> Option<&Organe> {
let context = &executor.context();
context.get_organe_at_uid(&self.organe_ref)
}
field organe_ref() -> Option<&str> {
Some(self.organe_ref.as_str())
}
field uid() -> &str {
......@@ -921,8 +951,23 @@ graphql_object!(Decision: Context |&self| {
&self.libelle_acte
}
field organe_ref() -> &str {
&self.organe_ref
field organe(&executor) -> Option<&Organe> {
let context = &executor.context();
context.get_organe_at_uid(&self.organe_ref)
}
field organe_ref() -> Option<&str> {
Some(self.organe_ref.as_str())
}
field reunion(&executor) -> Option<&Reunion> {
match &self.reunion_ref {
None => None,
Some(ref reunion_ref) => {
let context = &executor.context();
context.get_reunion_at_uid(&reunion_ref)
},
}
}
field reunion_ref() -> Option<&str> {
......@@ -936,16 +981,44 @@ graphql_object!(Decision: Context |&self| {
&self.statut_conclusion
}
field textes_associes() -> &Option<TextesAssocies> {
&self.textes_associes
field textes_associes() -> Vec<&TexteAssocie> {
match &self.textes_associes {
None => vec![],
Some(ref textes_associes) => {
textes_associes.textes_associes
.iter()
.collect()
},
}
}
field uid() -> &str {
&self.uid
}
field vote_refs() -> &Option<VoteRefs> {
&self.vote_refs
field vote_refs() -> Vec<&str> {
match &self.vote_refs {
None => vec![],
Some(ref vote_refs) => {
vote_refs.vote_refs
.iter()
.map(|ref vote_ref| vote_ref.as_str())
.collect()
},
}
}
field votes(&executor) -> Vec<&Scrutin> {
match &self.vote_refs {
None => vec![],
Some(ref vote_refs) => {
let context = &executor.context();
vote_refs.vote_refs
.iter()
.filter_map(|ref vote_ref| context.get_scrutin_at_uid(&vote_ref))
.collect()
},
}
}
});
......@@ -987,16 +1060,42 @@ graphql_object!(DecisionMotionCensure: Context |&self| {
&self.libelle_acte
}
field organe_ref() -> &str {
&self.organe_ref
field organe(&executor) -> Option<&Organe> {
let context = &executor.context();
context.get_organe_at_uid(&self.organe_ref)
}
field organe_ref() -> Option<&str> {
Some(self.organe_ref.as_str())
}
field uid() -> &str {
&self.uid
}
field vote_refs() -> &Option<VoteRefs> {
&self.vote_refs
field vote_refs() -> Vec<&str> {
match &self.vote_refs {
None => vec![],
Some(ref vote_refs) => {
vote_refs.vote_refs
.iter()
.map(|ref vote_ref| vote_ref.as_str())
.collect()
},
}
}
field votes(&executor) -> Vec<&Scrutin> {
match &self.vote_refs {
None => vec![],
Some(ref vote_refs) => {
let context = &executor.context();
vote_refs.vote_refs
.iter()
.filter_map(|ref vote_ref| context.get_scrutin_at_uid(&vote_ref))
.collect()
},
}
}
});
......@@ -1040,8 +1139,13 @@ graphql_object!(DecisionRecevabiliteBureau: Context |&self| {
&self.libelle_acte
}
field organe_ref() -> &str {
&self.organe_ref
field organe(&executor) -> Option<&Organe> {
let context = &executor.context();
context.get_organe_at_uid(&self.organe_ref)
}
field organe_ref() -> Option<&str> {
Some(self.organe_ref.as_str())
}
field uid() -> &str {
......@@ -1082,8 +1186,13 @@ graphql_object!(DeclarationGouvernement: Context |&self| {
&self.libelle_acte
}
field organe_ref() -> &str {
&self.organe_ref
field organe(&executor) -> Option<&Organe> {
let context = &executor.context();
context.get_organe_at_uid(&self.organe_ref)
}
field organe_ref() -> Option<&str> {
Some(self.organe_ref.as_str())
}
field texte_associe_ref() -> &str {
......@@ -1142,8 +1251,18 @@ graphql_object!(DepotAccordInternational: Context |&self| {
&self.libelle_acte
}
field organe_ref() -> &str {
&self.organe_ref
field organe(&executor) -> Option<&Organe> {
let context = &executor.context();
context.get_organe_at_uid(&self.organe_ref)
}
field organe(&executor) -> Option<&Organe> {
let context = &executor.context();
context.get_organe_at_uid(&self.organe_ref)
}
field organe_ref() -> Option<&str> {
Some(self.organe_ref.as_str())
}
field texte_associe_ref() -> &str {
......@@ -1198,8 +1317,13 @@ graphql_object!(DepotAvisConseilEtat: Context |&self| {
&self.libelle_acte
}
field organe_ref() -> &str {
&self.organe_ref
field organe(&executor) -> Option<&Organe> {
let context = &executor.context();
context.get_organe_at_uid(&self.organe_ref)
}
field organe_ref() -> Option<&str> {
Some(self.organe_ref.as_str())
}
field texte_associe_ref() -> &str {
......@@ -1254,8 +1378,13 @@ graphql_object!(DepotInitiative: Context |&self| {
&self.libelle_acte
}
field organe_ref() -> &str {
&self.organe_ref
field organe(&executor) -> Option<&Organe> {
let context = &executor.context();
context.get_organe_at_uid(&self.organe_ref)
}
field organe_ref() -> Option<&str> {
Some(self.organe_ref.as_str())
}
field texte_associe_ref() -> &str {
......@@ -1311,8 +1440,13 @@ graphql_object!(DepotInitiativeNavette: Context |&self| {
&self.libelle_acte
}
field organe_ref() -> &str {
&self.organe_ref
field organe(&executor) -> Option<&Organe> {
let context = &executor.context();
context.get_organe_at_uid(&self.organe_ref)
}
field organe_ref() -> Option<&str> {
Some(self.organe_ref.as_str())
}
field provenance() -> &str {
......@@ -1383,8 +1517,13 @@ graphql_object!(DepotLettreRectificative: Context |&self| {
&self.libelle_acte
}
field organe_ref() -> &str {
&self.organe_ref
field organe(&executor) -> Option<&Organe> {
let context = &executor.context();
context.get_organe_at_uid(&self.organe_ref)
}
field organe_ref() -> Option<&str> {
Some(self.organe_ref.as_str())
}
field texte_associe_ref() -> &str {
......@@ -1446,8 +1585,13 @@ graphql_object!(DepotMotionCensure: Context |&self| {
&self.libelle_acte
}
field organe_ref() -> &str {
&self.organe_ref
field organe(&executor) -> Option<&Organe> {
let context = &executor.context();
context.get_organe_at_uid(&self.organe_ref)
}
field organe_ref() -> Option<&str> {
Some(self.organe_ref.as_str())
}
field type_motion_censure() -> &Codier {
......@@ -1493,8 +1637,13 @@ graphql_object!(DepotMotionReferendaire: Context |&self| {
&self.libelle_acte
}
field organe_ref() -> &str {
&self.organe_ref
field organe(&executor) -> Option<&Organe> {
let context = &executor.context();
context.get_organe_at_uid(&self.organe_ref)
}
field organe_ref() -> Option<&str> {
Some(self.organe_ref.as_str())
}
field uid() -> &str {
......@@ -1535,8 +1684,13 @@ graphql_object!(DepotRapport: Context |&self| {
&self.libelle_acte
}
field organe_ref() -> &str {
&self.organe_ref
field organe(&executor) -> Option<&Organe> {
let context = &executor.context();
context.get_organe_at_uid(&self.organe_ref)
}
field organe_ref() -> Option<&str> {
Some(self.organe_ref.as_str())
}
field texte_adopte() -> Option<&str> {
......@@ -1607,8 +1761,13 @@ graphql_object!(DiscussionCommission: Context |&self| {
}
}
field organe_ref() -> &str {
&self.organe_ref
field organe(&executor) -> Option<&Organe> {
let context = &executor.context();
context.get_organe_at_uid(&self.organe_ref)
}
field organe_ref() -> Option<&str> {
Some(self.organe_ref.as_str())
}
field reunion_ref() -> Option<&str> {
......@@ -1660,8 +1819,13 @@ graphql_object!(DiscussionSeancePublique: Context |&self| {
Some(self.odj_ref.as_str())
}
field organe_ref() -> &str {
&self.organe_ref
field organe(&executor) -> Option<&Organe> {
let context = &executor.context();
context.get_organe_at_uid(&self.organe_ref)
}
field organe_ref() -> Option<&str> {
Some(self.organe_ref.as_str())
}
field reunion_ref() -> Option<&str> {
......@@ -1735,6 +1899,16 @@ graphql_object!(Etape: Context |&self| {
&self.libelle_acte
}
field organe(&executor) -> Option<&Organe> {
match &self.organe_ref {
None => None,
Some(ref organe_ref) => {
let context = &executor.context();
context.get_organe_at_uid(organe_ref)
},
}
}
field organe_ref() -> Option<&str> {
match &self.organe_ref {
None => None,
......@@ -1784,8 +1958,13 @@ graphql_object!(EtudeImpact: Context |&self| {
&self.libelle_acte
}
field organe_ref() -> &str {
&self.organe_ref
field organe(&executor) -> Option<&Organe> {
let context = &executor.context();
context.get_organe_at_uid(&self.organe_ref)
}
field organe_ref() -> Option<&str> {
Some(self.organe_ref.as_str())
}
field texte_associe_ref() -> &str {
......@@ -1933,8 +2112,13 @@ graphql_object!(MotionProcedure: Context |&self| {
&self.libelle_acte
}
field organe_ref() -> &str {
&self.organe_ref
field organe(&executor) -> Option<&Organe> {
let context = &executor.context();
context.get_organe_at_uid(&self.organe_ref)
}
field organe_ref() -> Option<&str> {
Some(self.organe_ref.as_str())
}
field type_motion() -> &Codier {
......@@ -1977,8 +2161,13 @@ graphql_object!(NominRapporteurs: Context |&self| {
&self.libelle_acte
}
field organe_ref() -> &str {
&self.organe_ref
field organe(&executor) -> Option<&Organe> {
let context = &executor.context();
context.get_organe_at_uid(&self.organe_ref)
}
field organe_ref() -> Option<&str> {
Some(self.organe_ref.as_str())
}
field rapporteurs() -> &Rapporteurs {
......@@ -2039,8 +2228,13 @@ graphql_object!(ProcedureAcceleree: Context |&self| {
&self.libelle_acte
}
field organe_ref() -> &str {
&self.organe_ref
field organe(&executor) -> Option<&Organe> {
let context = &executor.context();
context.get_organe_at_uid(&self.organe_ref)
}
field organe_ref() -> Option<&str> {
Some(self.organe_ref.as_str())
}
field uid() -> &str {
......@@ -2106,8 +2300,13 @@ graphql_object!(Promulgation: Context |&self| {
&self.libelle_acte
}
field organe_ref() -> &str {
&self.organe_ref
field organe(&executor) -> Option<&Organe> {
let context = &executor.context();
context.get_organe_at_uid(&self.organe_ref)
}
field organe_ref() -> Option<&str> {
Some(self.organe_ref.as_str())
}
field reference_nor() -> Option<&str> {
......@@ -2188,8 +2387,13 @@ graphql_object!(RenvoiCmp: Context |&self| {
&self.libelle_acte
}
field organe_ref() -> &str {
&self.organe_ref
field organe(&executor) -> Option<&Organe> {
let context = &executor.context();
context.get_organe_at_uid(&self.organe_ref)
}
field organe_ref() -> Option<&str> {
Some(self.organe_ref.as_str())
}
field uid() -> &str {
......@@ -2226,8 +2430,13 @@ graphql_object!(RenvoiPrealable: Context |&self| {
&self.libelle_acte
}
field organe_ref() -> &str {
&self.organe_ref
field organe(&executor) -> Option<&Organe> {
let context = &executor.context();
context.get_organe_at_uid(&self.organe_ref)
}
field organe_ref() -> Option<&str> {
Some(self.organe_ref.as_str())
}
field uid() -> &str {
......@@ -2266,8 +2475,13 @@ graphql_object!(RetraitInitiative: Context |&self| {
&self.libelle_acte
}
field organe_ref() -> &str {
&self.organe_ref
field organe(&executor) -> Option<&Organe> {
let context = &executor.context();
context.get_organe_at_uid(&self.organe_ref)
}
field organe_ref() -> Option<&str> {
Some(self.organe_ref.as_str())
}
field texte_associe_ref() -> &str {
......@@ -2320,8 +2534,13 @@ graphql_object!(SaisieComAvis: Context |&self| {
&self.libelle_acte
}
field organe_ref() -> &str {
&self.organe_ref
field organe(&executor) -> Option<&Organe> {
let context = &executor.context();
context.get_organe_at_uid(&self.organe_ref)
}
field organe_ref() -> Option<&str> {
Some(self.organe_ref.as_str())
}
field uid() -> &str {
......@@ -2358,8 +2577,13 @@ graphql_object!(SaisieComFond: Context |&self| {
&self.libelle_acte
}
field organe_ref() -> &str {
&self.organe_ref
field organe(&executor) -> Option<&Organe> {
let context = &executor.context();
context.get_organe_at_uid(&self.organe_ref)
}
field organe_ref() -> Option<&str> {
Some(self.organe_ref.as_str())
}
field uid() -> &str {
......@@ -2412,8 +2636,13 @@ graphql_object!(SaisineConseilConstit: Context |&self| {
&self.motif
}
field organe_ref() -> &str {
&self.organe_ref
field organe(&executor) -> Option<&Organe> {
let context = &executor.context();
context.get_organe_at_uid(&self.organe_ref)
}
field organe_ref() -> Option<&str> {
Some(self.organe_ref.as_str())
}
field uid() -> &str {
......@@ -2421,7 +2650,7 @@ graphql_object!(SaisineConseilConstit: Context |&self| {
}
});
#[derive(Clone, Debug, Deserialize, GraphQLObject)]
#[derive(Clone, Debug, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct TexteAssocie {
#[serde(rename = "refTexteAssocie")]
......@@ -2430,6 +2659,21 @@ pub struct TexteAssocie {
pub type_texte: String,
}
graphql_object!(TexteAssocie: Context |&self| {
field ref_texte_associe() -> &str {
&self.ref_texte_associe
}
field texte_associe(&executor) -> Option<&Document> {
let context = &executor.context();
context.get_document_at_uid(&self.ref_texte_associe)
}
field type_texte() -> &str {
&self.type_texte
}
});
#[derive(Clone, Debug, Deserialize, GraphQLObject)]
#[serde(deny_unknown_fields)]
pub struct TexteEuropeen {
......@@ -2439,16 +2683,16 @@ pub struct TexteEuropeen {
pub type_texte_europeen: String,
}
#[derive(Clone, Debug, Deserialize, GraphQLObject)]
#[derive(Clone, Debug, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct TextesAssocies {
#[serde(default, deserialize_with = "map_to_vec", rename = "texteAssocie")]
pub textes_associes: Vec<TexteAssocie>,
}