pub async fn sync_buildings(db: &Database, buildings: BTreeMap<String, BuildingConfig>) {
    // Get everything we need to authenticate with GSuite.
    // Initialize the GSuite client.
    let gsuite_customer = env::var("GADMIN_ACCOUNT_ID").unwrap();
    let token = get_gsuite_token("").await;
    let gsuite = GSuite::new(&gsuite_customer, GSUITE_DOMAIN, token);

    // Get the existing google buildings.
    let gsuite_buildings = gsuite.list_buildings().await.unwrap();

    // Get all the buildings.
    let db_buildings = Buildings::get_from_db(db);
    // Create a BTreeMap
    let mut building_map: BTreeMap<String, Building> = Default::default();
    for u in db_buildings {
        building_map.insert(u.name.to_string(), u);
    }
    // Sync buildings.
    for (_, mut building) in buildings {
        building.expand();

        building.upsert(db).await;

        // Remove the building from the BTreeMap.
        building_map.remove(&building.name);
    }
    // Remove any buildings that should no longer be in the database.
    // This is found by the remaining buildings that are in the map since we removed
    // the existing repos from the map above.
    for (name, building) in building_map {
        println!("deleting building {} from the database, gsuite, etc", name);

        building.delete(db).await;

        // Delete the building from GSuite.
        gsuite.delete_building(&name).await.unwrap_or_else(|e| panic!("deleting building {} from gsuite failed: {}", name, e));
        println!("deleted building from gsuite: {}", name);
    }
    println!("updated configs buildings in the database");

    // Update the buildings in GSuite.
    // Get all the buildings.
    let db_buildings = Buildings::get_from_db(db);
    // Create a BTreeMap
    let mut building_map: BTreeMap<String, Building> = Default::default();
    for u in db_buildings {
        building_map.insert(u.name.to_string(), u);
    }
    for b in gsuite_buildings {
        let id = b.id.to_string();

        // Check if we have that building already in our database.
        let building: Building;
        match building_map.get(&id) {
            Some(val) => building = val.clone(),
            None => {
                // If the building does not exist in our map we need to delete
                // them from GSuite.
                println!("deleting building {} from gsuite", id);
                gsuite.delete_building(&id).await.unwrap_or_else(|e| panic!("deleting building {} from gsuite failed: {}", id, e));

                println!("deleted building from gsuite: {}", id);
                continue;
            }
        }

        // Update the building with the settings from the database for the building.
        let new_b = update_gsuite_building(&b, &building, &id);

        // Update the building with the given settings.
        gsuite.update_building(&new_b).await.unwrap_or_else(|e| panic!("updating building {} in gsuite failed: {}", id, e));

        // Remove the building from the database map and continue.
        // This allows us to add all the remaining new building after.
        building_map.remove(&id);

        println!("updated building from gsuite: {}", id);
    }

    // Create any remaining buildings from the database that we do not have in GSuite.
    for (id, building) in building_map {
        // Create the building.
        let b: GSuiteBuilding = Default::default();

        let new_b = update_gsuite_building(&b, &building, &id);

        gsuite.create_building(&new_b).await.unwrap_or_else(|e| panic!("creating building {} in gsuite failed: {}", id, e));

        println!("created building from gsuite: {}", id);
    }

    // Update buildings in airtable.
    Buildings::get_from_db(db).update_airtable().await;
}
/// Sync our buildings with our database and then update Airtable from the database.
Sync our buildings with our database and then update Airtable from the database.
Sync our buildings with our database and then update Airtable from the database .
pub async fn sync_buildings(db: &Database, buildings: BTreeMap<String, BuildingConfig>) {
    // Get everything we need to authenticate with GSuite.
    // Initialize the GSuite client.
    let gsuite_customer = env::var("GADMIN_ACCOUNT_ID").unwrap();
    let token = get_gsuite_token("").await;
    let gsuite = GSuite::new(&gsuite_customer, GSUITE_DOMAIN, token);
    // Get the existing google buildings.
    let gsuite_buildings = gsuite.list_buildings().await.unwrap();
    // Get all the buildings.
    let db_buildings = Buildings::get_from_db(db);
    // Create a BTreeMap
    let mut building_map: BTreeMap<String, Building> = Default::default();
    for u in db_buildings {
        building_map.insert(u.name.to_string(), u);
    }
    // Sync buildings.
    for (_, mut building) in buildings {
        building.expand();
        building.upsert(db).await;
        // Remove the building from the BTreeMap.
        building_map.remove(&building.name);
    }
    // Remove any buildings that should no longer be in the database.
    // This is found by the remaining buildings that are in the map since we removed
    // the existing repos from the map above.
    for (name, building) in building_map {
        println!("deleting building {} from the database, gsuite, etc", name);
        building.delete(db).await;
        // Delete the building from GSuite.
        gsuite.delete_building(&name).await.unwrap_or_else(|e| panic!("deleting building {} from gsuite failed: {}", name, e));
        println!("deleted building from gsuite: {}", name);
    }
    println!("updated configs buildings in the database");
    // Update the buildings in GSuite.
    // Get all the buildings.
    let db_buildings = Buildings::get_from_db(db);
    // Create a BTreeMap
    let mut building_map: BTreeMap<String, Building> = Default::default();
    for u in db_buildings {
        building_map.insert(u.name.to_string(), u);
    }
    for b in gsuite_buildings {
        let id = b.id.to_string();
        // Check if we have that building already in our database.
        let building: Building;
        match building_map.get(&id) {
            Some(val) => building = val.clone(),
            None => {
                // If the building does not exist in our map we need to delete
                // them from GSuite.
                println!("deleting building {} from gsuite", id);
                gsuite.delete_building(&id).await.unwrap_or_else(|e| panic!("deleting building {} from gsuite failed: {}", id, e));
                println!("deleted building from gsuite: {}", id);
                continue;
            }
        }
        // Update the building with the settings from the database for the building.
        let new_b = update_gsuite_building(&b, &building, &id);
        // Update the building with the given settings.
        gsuite.update_building(&new_b).await.unwrap_or_else(|e| panic!("updating building {} in gsuite failed: {}", id, e));
        // Remove the building from the database map and continue.
        // This allows us to add all the remaining new building after.
        building_map.remove(&id);
        println!("updated building from gsuite: {}", id);
    }
    // Create any remaining buildings from the database that we do not have in GSuite.
    for (id, building) in building_map {
        // Create the building.
        let b: GSuiteBuilding = Default::default();
        let new_b = update_gsuite_building(&b, &building, &id);
        gsuite.create_building(&new_b).await.unwrap_or_else(|e| panic!("creating building {} in gsuite failed: {}", id, e));
        println!("created building from gsuite: {}", id);
    }
    // Update buildings in airtable.
    Buildings::get_from_db(db).update_airtable().await;
}
pub async fn sync_buildings ( db : & Database , buildings : BTreeMap < String , BuildingConfig > ) { // Get everything we need to authenticate with GSuite. // Initialize the GSuite client. let gsuite_customer = env :: var ( " " ) . unwrap ( ) ; let token = get_gsuite_token ( " " ) . await ; let gsuite = GSuite :: new ( & gsuite_customer , GSUITE_DOMAIN , token ) ; // Get the existing google buildings. let gsuite_buildings = gsuite . list_buildings ( ) . await . unwrap ( ) ; // Get all the buildings. let db_buildings = Buildings :: get_from_db ( db ) ; // Create a BTreeMap let mut building_map : BTreeMap < String , Building > = Default :: default ( ) ; for u in db_buildings { building_map . insert ( u . name . to_string ( ) , u ) ; } // Sync buildings. for ( _ , mut building ) in buildings { building . expand ( ) ; building . upsert ( db ) . await ; // Remove the building from the BTreeMap. building_map . remove ( & building . name ) ; } // Remove any buildings that should no longer be in the database. // This is found by the remaining buildings that are in the map since we removed // the existing repos from the map above. for ( name , building ) in building_map { println ! ( " " name ) ; building . delete ( db ) . await ; // Delete the building from GSuite. gsuite . delete_building ( & name ) . await . unwrap_or_else ( | e | panic ! ( " " name e ) ) ; println ! ( " " name ) ; } println ! ( " " ) ; // Update the buildings in GSuite. // Get all the buildings. let db_buildings = Buildings :: get_from_db ( db ) ; // Create a BTreeMap let mut building_map : BTreeMap < String , Building > = Default :: default ( ) ; for u in db_buildings { building_map . insert ( u . name . to_string ( ) , u ) ; } for b in gsuite_buildings { let id = b . id . to_string ( ) ; // Check if we have that building already in our database. let building : Building ; match building_map . get ( & id ) { Some ( val ) => building = val . clone ( ) , None => { // If the building does not exist in our map we need to delete // them from GSuite. println ! ( " " id ) ; gsuite . delete_building ( & id ) . await . unwrap_or_else ( | e | panic ! ( " " id e ) ) ; println ! ( " " id ) ; continue ; } } // Update the building with the settings from the database for the building. let new_b = update_gsuite_building ( & b , & building , & id ) ; // Update the building with the given settings. gsuite . update_building ( & new_b ) . await . unwrap_or_else ( | e | panic ! ( " " id e ) ) ; // Remove the building from the database map and continue. // This allows us to add all the remaining new building after. building_map . remove ( & id ) ; println ! ( " " id ) ; } // Create any remaining buildings from the database that we do not have in GSuite. for ( id , building ) in building_map { // Create the building. let b : GSuiteBuilding = Default :: default ( ) ; let new_b = update_gsuite_building ( & b , & building , & id ) ; gsuite . create_building ( & new_b ) . await . unwrap_or_else ( | e | panic ! ( " " id e ) ) ; println ! ( " " id ) ; } // Update buildings in airtable. Buildings :: get_from_db ( db ) . update_airtable ( ) . await ; }
Sync our buildings with our database and then update Airtable from the database.
Sync our buildings with our database and then update Airtable from the database .
db
&Database
buildings
BTreeMap<String, BuildingConfig>
db
&Database
buildings
BTreeMap<String, BuildingConfig>