use chrono::NaiveDate;
use serde::{Deserialize, Serialize};
use uuid::Uuid;
#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub enum GovernmentLevel {
Federal,
State,
County,
Municipal,
SpecialDistrict,
}
#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub enum Branch {
Executive,
Legislative,
Judicial,
}
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct Term {
pub start_date: NaiveDate,
pub start_date_sources: Vec<String>,
pub end_date: Option<NaiveDate>,
pub end_date_sources: Vec<String>,
pub office_title: String,
pub office_title_sources: Vec<String>,
pub level: GovernmentLevel,
pub level_sources: Vec<String>,
pub location: String,
pub location_sources: Vec<String>,
pub political_party: String,
pub political_party_sources: Vec<String>,
}
#[derive(Debug, Deserialize, Serialize)]
#[cfg_attr(feature = "postgres", derive(sqlx::FromRow))]
pub struct Official {
pub birth: NaiveDate,
pub birth_sources: Vec<String>,
pub first_name: String,
pub first_name_sources: Vec<String>,
pub id: Uuid,
pub last_name: String,
pub last_name_sources: Vec<String>,
pub middle_name: Option<String>,
pub middle_name_sources: Vec<String>,
pub terms: Vec<Term>,
}
impl Official {
pub fn get_full_name(&self) -> String {
let middle_name_string = match &self.middle_name {
Some(name) => {
format!("{0} ", name)
}
None => String::from(""),
};
format!(
"{0} {1}{2}",
self.first_name, middle_name_string, self.last_name
)
} }
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_official_get_full_name() {
let official = Official {
birth: NaiveDate::from_ymd_opt(1997, 8, 6).unwrap(),
birth_sources: Vec::new(),
first_name: String::from("Austin"),
first_name_sources: Vec::new(),
id: Uuid::new_v4(),
last_name: String::from("Farrell"),
last_name_sources: Vec::new(),
middle_name: Some(String::from("Michael")),
middle_name_sources: Vec::new(),
terms: Vec::new(),
};
assert_eq!(
official.get_full_name(),
String::from("Austin Michael Farrell")
);
let official = Official {
birth: NaiveDate::from_ymd_opt(1997, 8, 6).unwrap(),
birth_sources: Vec::new(),
first_name: String::from("Austin"),
first_name_sources: Vec::new(),
id: Uuid::new_v4(),
last_name: String::from("Farrell"),
last_name_sources: Vec::new(),
middle_name: None,
middle_name_sources: Vec::new(),
terms: Vec::new(),
};
assert_eq!(official.get_full_name(), String::from("Austin Farrell"));
} }