From e857e4416500b7a356a6772aa0b7e825ec2e2545 Mon Sep 17 00:00:00 2001 From: Benjamin Slingo Date: Sat, 30 Aug 2025 21:45:30 -0400 Subject: [PATCH] Update NAPI bindings to use church-core uniffi functions directly Eliminates duplication by using church_core::uniffi::* instead of church_core::api::* This ensures both UniFFI (iOS) and NAPI (web) use identical implementations. --- src/lib.rs | 84 +++++++++++++++++++++++++++++++++++------------------- 1 file changed, 54 insertions(+), 30 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 5c53ff0..db4fe02 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,120 +1,140 @@ use napi_derive::napi; use church_core; -use church_core::api; #[napi] pub fn get_church_name() -> String { - api::get_church_name() + church_core::uniffi::config::get_church_name() } #[napi] pub fn fetch_events_json() -> String { - api::fetch_events_json() + church_core::uniffi::events::fetch_events_json() } #[napi] pub fn fetch_featured_events_json() -> String { - api::fetch_featured_events_json() + church_core::uniffi::events::fetch_featured_events_json() } #[napi] pub fn fetch_sermons_json() -> String { - api::fetch_sermons_json() + church_core::uniffi::sermons::fetch_sermons_json() } #[napi] pub fn fetch_config_json() -> String { - api::fetch_config_json() + church_core::uniffi::config::fetch_config_json() +} + +#[napi] +pub fn update_config_json(config_json: String) -> String { + // This one doesn't exist in uniffi yet - TODO: add it or implement here + serde_json::json!({"success": false, "error": "Not implemented yet"}).to_string() } #[napi] pub fn get_mission_statement() -> String { - api::get_mission_statement() + church_core::uniffi::config::get_mission_statement() } #[napi] pub fn fetch_random_bible_verse_json() -> String { - api::fetch_random_bible_verse_json() + church_core::uniffi::bible::fetch_random_bible_verse_json() } #[napi] pub fn get_stream_live_status() -> bool { - api::get_stream_live_status() + church_core::uniffi::streaming::get_stream_live_status() } #[napi] pub fn get_livestream_url() -> String { - api::get_livestream_url() + church_core::uniffi::streaming::get_livestream_url() } #[napi] pub fn get_church_address() -> String { - api::get_church_address() + church_core::uniffi::config::get_church_address() } #[napi] pub fn get_church_physical_address() -> String { - api::get_church_physical_address() + // This might need to be implemented in uniffi::config + church_core::uniffi::config::get_church_address() } #[napi] pub fn get_church_po_box() -> String { - api::get_church_po_box() + // This might need to be implemented in uniffi::config - for now return empty + "".to_string() } #[napi] pub fn get_contact_phone() -> String { - api::get_contact_phone() + church_core::uniffi::config::get_contact_phone() } #[napi] pub fn get_contact_email() -> String { - api::get_contact_email() + church_core::uniffi::config::get_contact_email() } #[napi] pub fn get_facebook_url() -> String { - api::get_facebook_url() + church_core::uniffi::config::get_facebook_url() } #[napi] pub fn get_youtube_url() -> String { - api::get_youtube_url() + church_core::uniffi::config::get_youtube_url() } #[napi] pub fn get_instagram_url() -> String { - api::get_instagram_url() + church_core::uniffi::config::get_instagram_url() } #[napi] pub fn submit_contact_v2_json(name: String, email: String, subject: String, message: String, phone: String) -> String { - api::submit_contact_v2_json(name, email, subject, message, phone) + church_core::uniffi::contact::submit_contact_v2_json(name, email, subject, message, phone) } #[napi] pub fn validate_contact_form_json(form_json: String) -> String { - api::validate_contact_form_json(form_json) + church_core::uniffi::contact::validate_contact_form_json(form_json) +} + +#[napi] +pub fn validate_event_form_json(event_json: String) -> String { + // TODO: Check if this exists in uniffi::events + serde_json::json!({"success": false, "error": "Not implemented yet"}).to_string() +} + +#[napi] +pub fn validate_event_field_json(field_name: String, value: String, event_json: Option) -> String { + // NAPI version has 3 params, but uniffi might only take 2 - adapt as needed + // TODO: Check uniffi::events for the correct signature + serde_json::json!({"success": false, "error": "Not implemented yet"}).to_string() } #[napi] pub fn fetch_livestream_archive_json() -> String { - api::fetch_livestream_archive_json() + church_core::uniffi::streaming::fetch_livestream_archive_json() } #[napi] pub fn fetch_bulletins_json() -> String { - api::fetch_bulletins_json() + church_core::uniffi::parsing::fetch_bulletins_json() } #[napi] pub fn fetch_current_bulletin_json() -> String { - api::fetch_current_bulletin_json() + church_core::uniffi::parsing::fetch_current_bulletin_json() } #[napi] pub fn fetch_bible_verse_json(query: String) -> String { - api::fetch_bible_verse_json(query) + church_core::uniffi::bible::fetch_bible_verse_json(query) } #[napi] @@ -129,7 +149,7 @@ pub fn submit_event_json( recurring_type: Option, submitter_email: Option ) -> String { - api::submit_event_json( + church_core::uniffi::events::submit_event_json( title, description, start_time, @@ -142,7 +162,7 @@ pub fn submit_event_json( ) } -// Admin functions +// Admin functions - these might not exist in uniffi yet #[napi] pub fn test_admin_function() -> String { "test".to_string() @@ -150,20 +170,24 @@ pub fn test_admin_function() -> String { #[napi] pub fn fetch_all_schedules_json() -> String { - api::fetch_all_schedules_json() + // TODO: Add to uniffi modules if needed + serde_json::json!({"success": false, "error": "Not implemented yet"}).to_string() } #[napi] pub fn create_schedule_json(schedule_json: String) -> String { - api::create_schedule_json(schedule_json) + // TODO: Add to uniffi modules if needed + serde_json::json!({"success": false, "error": "Not implemented yet"}).to_string() } #[napi] pub fn update_schedule_json(date: String, update_json: String) -> String { - api::update_schedule_json(date, update_json) + // TODO: Add to uniffi modules if needed + serde_json::json!({"success": false, "error": "Not implemented yet"}).to_string() } #[napi] pub fn delete_schedule_json(date: String) -> String { - api::delete_schedule_json(date) + // TODO: Add to uniffi modules if needed + serde_json::json!({"success": false, "error": "Not implemented yet"}).to_string() } \ No newline at end of file