Can get possible couple states through API
This commit is contained in:
		@@ -70,8 +70,8 @@ CREATE TABLE members (
 | 
			
		||||
CREATE TABLE couples (
 | 
			
		||||
    id SERIAL PRIMARY KEY,
 | 
			
		||||
    family_id integer NOT NULL REFERENCES families,
 | 
			
		||||
    wife integer NULL REFERENCES members,
 | 
			
		||||
    husband integer NULL REFERENCES members,
 | 
			
		||||
    wife integer NULL REFERENCES members ON DELETE SET NULL,
 | 
			
		||||
    husband integer NULL REFERENCES members ON DELETE SET NULL,
 | 
			
		||||
    state varchar(1) NULL,
 | 
			
		||||
    photo_id INTEGER NULL REFERENCES photos ON DELETE SET NULL,
 | 
			
		||||
    time_create BIGINT NOT NULL,
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,6 @@
 | 
			
		||||
use crate::app_config::{AppConfig, OIDCProvider};
 | 
			
		||||
use crate::constants::StaticConstraints;
 | 
			
		||||
use crate::models::{CoupleState, CoupleStateDesc};
 | 
			
		||||
use crate::utils::countries_utils;
 | 
			
		||||
use crate::utils::countries_utils::CountryCode;
 | 
			
		||||
use actix_web::{HttpResponse, Responder};
 | 
			
		||||
@@ -15,6 +16,7 @@ struct ServerConfig<'a> {
 | 
			
		||||
    mail: &'static str,
 | 
			
		||||
    oidc_providers: Vec<OIDCProvider<'a>>,
 | 
			
		||||
    countries: Vec<CountryCode>,
 | 
			
		||||
    couples_states: Vec<CoupleStateDesc>,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl Default for ServerConfig<'_> {
 | 
			
		||||
@@ -24,6 +26,7 @@ impl Default for ServerConfig<'_> {
 | 
			
		||||
            constraints: StaticConstraints::default(),
 | 
			
		||||
            oidc_providers: AppConfig::get().openid_providers(),
 | 
			
		||||
            countries: countries_utils::get_list(),
 | 
			
		||||
            couples_states: CoupleState::states_list(),
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -314,6 +314,13 @@ pub enum CoupleState {
 | 
			
		||||
    Divorced,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[derive(Debug, Clone, serde::Serialize)]
 | 
			
		||||
pub struct CoupleStateDesc {
 | 
			
		||||
    code: &'static str,
 | 
			
		||||
    fr: &'static str,
 | 
			
		||||
    en: &'static str,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl CoupleState {
 | 
			
		||||
    pub fn as_str(&self) -> &str {
 | 
			
		||||
        match self {
 | 
			
		||||
@@ -327,6 +334,31 @@ impl CoupleState {
 | 
			
		||||
    pub fn parse_str(s: &str) -> Option<Self> {
 | 
			
		||||
        serde_json::from_str(s).ok()
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    pub fn states_list() -> Vec<CoupleStateDesc> {
 | 
			
		||||
        vec![
 | 
			
		||||
            CoupleStateDesc {
 | 
			
		||||
                code: "N",
 | 
			
		||||
                fr: "Aucun",
 | 
			
		||||
                en: "None",
 | 
			
		||||
            },
 | 
			
		||||
            CoupleStateDesc {
 | 
			
		||||
                code: "E",
 | 
			
		||||
                fr: "Fiancés",
 | 
			
		||||
                en: "Engaged",
 | 
			
		||||
            },
 | 
			
		||||
            CoupleStateDesc {
 | 
			
		||||
                code: "M",
 | 
			
		||||
                fr: "Mariés",
 | 
			
		||||
                en: "Married",
 | 
			
		||||
            },
 | 
			
		||||
            CoupleStateDesc {
 | 
			
		||||
                code: "D",
 | 
			
		||||
                fr: "Divorcés",
 | 
			
		||||
                en: "Divorced",
 | 
			
		||||
            },
 | 
			
		||||
        ]
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[derive(Queryable, Debug, serde::Serialize)]
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user