pub async fn sync_conference_rooms(db: &Database, conference_rooms: BTreeMap<String, ResourceConfig>) {
    // 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 GSuite calendar resources.
    let g_suite_calendar_resources = gsuite.list_calendar_resources().await.unwrap();

    // Get all the conference_rooms.
    let db_conference_rooms = ConferenceRooms::get_from_db(db);
    // Create a BTreeMap
    let mut conference_room_map: BTreeMap<String, ConferenceRoom> = Default::default();
    for u in db_conference_rooms {
        conference_room_map.insert(u.name.to_string(), u);
    }
    // Sync conference_rooms.
    for (_, conference_room) in conference_rooms {
        conference_room.upsert(db).await;

        // Remove the conference_room from the BTreeMap.
        conference_room_map.remove(&conference_room.name);
    }
    // Remove any conference_rooms that should no longer be in the database.
    // This is found by the remaining conference_rooms that are in the map since we removed
    // the existing repos from the map above.
    for (name, room) in conference_room_map {
        println!("deleting conference room {} from the database", name);
        room.delete(db).await;
    }
    println!("updated configs conference_rooms in the database");

    // Update the conference_rooms in GSuite.
    // Get all the conference_rooms.
    let db_conference_rooms = ConferenceRooms::get_from_db(db);
    // Create a BTreeMap
    let mut conference_room_map: BTreeMap<String, ConferenceRoom> = Default::default();
    for u in db_conference_rooms {
        conference_room_map.insert(u.name.to_string(), u);
    }
    for r in g_suite_calendar_resources {
        let id = r.name.to_string();

        // Check if we have that resource already in our database.
        let resource: ConferenceRoom;
        match conference_room_map.get(&id) {
            Some(val) => resource = val.clone(),
            None => {
                // If the conference room does not exist in our map we need to delete
                // it from GSuite.
                println!("deleting conference room {} from gsuite", id);
                gsuite
                    .delete_calendar_resource(&r.id)
                    .await
                    .unwrap_or_else(|e| panic!("deleting conference room {} with id {} from gsuite failed: {}", id, r.id, e));

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

        // Update the resource with the settings from the database for the resource.
        let new_r = update_gsuite_calendar_resource(&r, &resource, &r.id);

        // Update the resource with the given settings.
        gsuite
            .update_calendar_resource(&new_r)
            .await
            .unwrap_or_else(|e| panic!("updating conference room {} in gsuite failed: {}", id, e));

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

        println!("updated conference room in gsuite: {}", id);
    }

    // Create any remaining resources from the database that we do not have in GSuite.
    for (id, resource) in conference_room_map {
        // Create the resource.
        let r: GSuiteCalendarResource = Default::default();

        let new_r = update_gsuite_calendar_resource(&r, &resource, &id);

        gsuite
            .create_calendar_resource(&new_r)
            .await
            .unwrap_or_else(|e| panic!("creating conference room {} in gsuite failed: {}", id, e));

        println!("created conference room in gsuite: {}", id);
    }

    // Update conference_rooms in airtable.
    ConferenceRooms::get_from_db(db).update_airtable().await;
}
/// Sync our conference_rooms with our database and then update Airtable from the database.
Sync our conference_rooms with our database and then update Airtable from the database.
Sync our conference_rooms with our database and then update Airtable from the database .
pub async fn sync_conference_rooms(db: &Database, conference_rooms: BTreeMap<String, ResourceConfig>) {
    // 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 GSuite calendar resources.
    let g_suite_calendar_resources = gsuite.list_calendar_resources().await.unwrap();
    // Get all the conference_rooms.
    let db_conference_rooms = ConferenceRooms::get_from_db(db);
    // Create a BTreeMap
    let mut conference_room_map: BTreeMap<String, ConferenceRoom> = Default::default();
    for u in db_conference_rooms {
        conference_room_map.insert(u.name.to_string(), u);
    }
    // Sync conference_rooms.
    for (_, conference_room) in conference_rooms {
        conference_room.upsert(db).await;
        // Remove the conference_room from the BTreeMap.
        conference_room_map.remove(&conference_room.name);
    }
    // Remove any conference_rooms that should no longer be in the database.
    // This is found by the remaining conference_rooms that are in the map since we removed
    // the existing repos from the map above.
    for (name, room) in conference_room_map {
        println!("deleting conference room {} from the database", name);
        room.delete(db).await;
    }
    println!("updated configs conference_rooms in the database");
    // Update the conference_rooms in GSuite.
    // Get all the conference_rooms.
    let db_conference_rooms = ConferenceRooms::get_from_db(db);
    // Create a BTreeMap
    let mut conference_room_map: BTreeMap<String, ConferenceRoom> = Default::default();
    for u in db_conference_rooms {
        conference_room_map.insert(u.name.to_string(), u);
    }
    for r in g_suite_calendar_resources {
        let id = r.name.to_string();
        // Check if we have that resource already in our database.
        let resource: ConferenceRoom;
        match conference_room_map.get(&id) {
            Some(val) => resource = val.clone(),
            None => {
                // If the conference room does not exist in our map we need to delete
                // it from GSuite.
                println!("deleting conference room {} from gsuite", id);
                gsuite
                    .delete_calendar_resource(&r.id)
                    .await
                    .unwrap_or_else(|e| panic!("deleting conference room {} with id {} from gsuite failed: {}", id, r.id, e));
                println!("deleted conference room from gsuite: {}", id);
                continue;
            }
        }
        // Update the resource with the settings from the database for the resource.
        let new_r = update_gsuite_calendar_resource(&r, &resource, &r.id);
        // Update the resource with the given settings.
        gsuite
            .update_calendar_resource(&new_r)
            .await
            .unwrap_or_else(|e| panic!("updating conference room {} in gsuite failed: {}", id, e));
        // Remove the resource from the database map and continue.
        // This allows us to add all the remaining new resource after.
        conference_room_map.remove(&id);
        println!("updated conference room in gsuite: {}", id);
    }
    // Create any remaining resources from the database that we do not have in GSuite.
    for (id, resource) in conference_room_map {
        // Create the resource.
        let r: GSuiteCalendarResource = Default::default();
        let new_r = update_gsuite_calendar_resource(&r, &resource, &id);
        gsuite
            .create_calendar_resource(&new_r)
            .await
            .unwrap_or_else(|e| panic!("creating conference room {} in gsuite failed: {}", id, e));
        println!("created conference room in gsuite: {}", id);
    }
    // Update conference_rooms in airtable.
    ConferenceRooms::get_from_db(db).update_airtable().await;
}
pub async fn sync_conference_rooms ( db : & Database , conference_rooms : BTreeMap < String , ResourceConfig > ) { // 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 GSuite calendar resources. let g_suite_calendar_resources = gsuite . list_calendar_resources ( ) . await . unwrap ( ) ; // Get all the conference_rooms. let db_conference_rooms = ConferenceRooms :: get_from_db ( db ) ; // Create a BTreeMap let mut conference_room_map : BTreeMap < String , ConferenceRoom > = Default :: default ( ) ; for u in db_conference_rooms { conference_room_map . insert ( u . name . to_string ( ) , u ) ; } // Sync conference_rooms. for ( _ , conference_room ) in conference_rooms { conference_room . upsert ( db ) . await ; // Remove the conference_room from the BTreeMap. conference_room_map . remove ( & conference_room . name ) ; } // Remove any conference_rooms that should no longer be in the database. // This is found by the remaining conference_rooms that are in the map since we removed // the existing repos from the map above. for ( name , room ) in conference_room_map { println ! ( " " name ) ; room . delete ( db ) . await ; } println ! ( " " ) ; // Update the conference_rooms in GSuite. // Get all the conference_rooms. let db_conference_rooms = ConferenceRooms :: get_from_db ( db ) ; // Create a BTreeMap let mut conference_room_map : BTreeMap < String , ConferenceRoom > = Default :: default ( ) ; for u in db_conference_rooms { conference_room_map . insert ( u . name . to_string ( ) , u ) ; } for r in g_suite_calendar_resources { let id = r . name . to_string ( ) ; // Check if we have that resource already in our database. let resource : ConferenceRoom ; match conference_room_map . get ( & id ) { Some ( val ) => resource = val . clone ( ) , None => { // If the conference room does not exist in our map we need to delete // it from GSuite. println ! ( " " id ) ; gsuite . delete_calendar_resource ( & r . id ) . await . unwrap_or_else ( | e | panic ! ( " " id r id e ) ) ; println ! ( " " id ) ; continue ; } } // Update the resource with the settings from the database for the resource. let new_r = update_gsuite_calendar_resource ( & r , & resource , & r . id ) ; // Update the resource with the given settings. gsuite . update_calendar_resource ( & new_r ) . await . unwrap_or_else ( | e | panic ! ( " " id e ) ) ; // Remove the resource from the database map and continue. // This allows us to add all the remaining new resource after. conference_room_map . remove ( & id ) ; println ! ( " " id ) ; } // Create any remaining resources from the database that we do not have in GSuite. for ( id , resource ) in conference_room_map { // Create the resource. let r : GSuiteCalendarResource = Default :: default ( ) ; let new_r = update_gsuite_calendar_resource ( & r , & resource , & id ) ; gsuite . create_calendar_resource ( & new_r ) . await . unwrap_or_else ( | e | panic ! ( " " id e ) ) ; println ! ( " " id ) ; } // Update conference_rooms in airtable. ConferenceRooms :: get_from_db ( db ) . update_airtable ( ) . await ; }
Sync our conference_rooms with our database and then update Airtable from the database.
Sync our conference_rooms with our database and then update Airtable from the database .
db
&Database
conference_rooms
BTreeMap<String, ResourceConfig>
db
&Database
conference_rooms
BTreeMap<String, ResourceConfig>