auto update mailing list subscribers in teh database
@@ -7,6 +7,7 @@ use crate::airtable::{
airtable_api_key, AIRTABLE_BASE_ID_CUSTOMER_LEADS, AIRTABLE_GRID_VIEW,
AIRTABLE_MAILING_LIST_SIGNUPS_TABLE,
};
+use crate::db::Database;
use crate::models::NewMailingListSubscriber;
/// Get all the mailing list subscribers from Airtable.
@@ -182,3 +183,26 @@ pub struct MailchimpWebhookGrouping {
#[serde(skip_serializing_if = "Option::is_none")]
pub groups: Option<String>,
}
+
+// Sync the mailing list subscribers with our database.
+pub async fn refresh_db_mailing_list_subscribers() {
+ let mailing_list_subscribers = get_all_subscribers().await;
+
+ // Initialize our database.
+ let db = Database::new();
+
+ // Sync mailing_list_subscribers.
+ for mailing_list_subscriber in mailing_list_subscribers {
+ db.upsert_mailing_list_subscriber(&mailing_list_subscriber);
+ }
+}
+
+#[cfg(test)]
+mod tests {
+ use crate::mailing_list::refresh_db_mailing_list_subscribers;
+
+ #[tokio::test(threaded_scheduler)]
+ async fn test_mailing_list_subscribers() {
+ refresh_db_mailing_list_subscribers().await;
+ }
+}
