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.
This commit is contained in:
Benjamin Slingo 2025-08-30 21:45:30 -04:00
parent e63e617749
commit e857e44165

View file

@ -1,120 +1,140 @@
use napi_derive::napi; use napi_derive::napi;
use church_core; use church_core;
use church_core::api;
#[napi] #[napi]
pub fn get_church_name() -> String { pub fn get_church_name() -> String {
api::get_church_name() church_core::uniffi::config::get_church_name()
} }
#[napi] #[napi]
pub fn fetch_events_json() -> String { pub fn fetch_events_json() -> String {
api::fetch_events_json() church_core::uniffi::events::fetch_events_json()
} }
#[napi] #[napi]
pub fn fetch_featured_events_json() -> String { pub fn fetch_featured_events_json() -> String {
api::fetch_featured_events_json() church_core::uniffi::events::fetch_featured_events_json()
} }
#[napi] #[napi]
pub fn fetch_sermons_json() -> String { pub fn fetch_sermons_json() -> String {
api::fetch_sermons_json() church_core::uniffi::sermons::fetch_sermons_json()
} }
#[napi] #[napi]
pub fn fetch_config_json() -> String { 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] #[napi]
pub fn get_mission_statement() -> String { pub fn get_mission_statement() -> String {
api::get_mission_statement() church_core::uniffi::config::get_mission_statement()
} }
#[napi] #[napi]
pub fn fetch_random_bible_verse_json() -> String { pub fn fetch_random_bible_verse_json() -> String {
api::fetch_random_bible_verse_json() church_core::uniffi::bible::fetch_random_bible_verse_json()
} }
#[napi] #[napi]
pub fn get_stream_live_status() -> bool { pub fn get_stream_live_status() -> bool {
api::get_stream_live_status() church_core::uniffi::streaming::get_stream_live_status()
} }
#[napi] #[napi]
pub fn get_livestream_url() -> String { pub fn get_livestream_url() -> String {
api::get_livestream_url() church_core::uniffi::streaming::get_livestream_url()
} }
#[napi] #[napi]
pub fn get_church_address() -> String { pub fn get_church_address() -> String {
api::get_church_address() church_core::uniffi::config::get_church_address()
} }
#[napi] #[napi]
pub fn get_church_physical_address() -> String { 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] #[napi]
pub fn get_church_po_box() -> String { 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] #[napi]
pub fn get_contact_phone() -> String { pub fn get_contact_phone() -> String {
api::get_contact_phone() church_core::uniffi::config::get_contact_phone()
} }
#[napi] #[napi]
pub fn get_contact_email() -> String { pub fn get_contact_email() -> String {
api::get_contact_email() church_core::uniffi::config::get_contact_email()
} }
#[napi] #[napi]
pub fn get_facebook_url() -> String { pub fn get_facebook_url() -> String {
api::get_facebook_url() church_core::uniffi::config::get_facebook_url()
} }
#[napi] #[napi]
pub fn get_youtube_url() -> String { pub fn get_youtube_url() -> String {
api::get_youtube_url() church_core::uniffi::config::get_youtube_url()
} }
#[napi] #[napi]
pub fn get_instagram_url() -> String { pub fn get_instagram_url() -> String {
api::get_instagram_url() church_core::uniffi::config::get_instagram_url()
} }
#[napi] #[napi]
pub fn submit_contact_v2_json(name: String, email: String, subject: String, message: String, phone: String) -> String { 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] #[napi]
pub fn validate_contact_form_json(form_json: String) -> String { 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>) -> 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] #[napi]
pub fn fetch_livestream_archive_json() -> String { pub fn fetch_livestream_archive_json() -> String {
api::fetch_livestream_archive_json() church_core::uniffi::streaming::fetch_livestream_archive_json()
} }
#[napi] #[napi]
pub fn fetch_bulletins_json() -> String { pub fn fetch_bulletins_json() -> String {
api::fetch_bulletins_json() church_core::uniffi::parsing::fetch_bulletins_json()
} }
#[napi] #[napi]
pub fn fetch_current_bulletin_json() -> String { pub fn fetch_current_bulletin_json() -> String {
api::fetch_current_bulletin_json() church_core::uniffi::parsing::fetch_current_bulletin_json()
} }
#[napi] #[napi]
pub fn fetch_bible_verse_json(query: String) -> String { 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] #[napi]
@ -129,7 +149,7 @@ pub fn submit_event_json(
recurring_type: Option<String>, recurring_type: Option<String>,
submitter_email: Option<String> submitter_email: Option<String>
) -> String { ) -> String {
api::submit_event_json( church_core::uniffi::events::submit_event_json(
title, title,
description, description,
start_time, start_time,
@ -142,7 +162,7 @@ pub fn submit_event_json(
) )
} }
// Admin functions // Admin functions - these might not exist in uniffi yet
#[napi] #[napi]
pub fn test_admin_function() -> String { pub fn test_admin_function() -> String {
"test".to_string() "test".to_string()
@ -150,20 +170,24 @@ pub fn test_admin_function() -> String {
#[napi] #[napi]
pub fn fetch_all_schedules_json() -> String { 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] #[napi]
pub fn create_schedule_json(schedule_json: String) -> String { 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] #[napi]
pub fn update_schedule_json(date: String, update_json: String) -> String { 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] #[napi]
pub fn delete_schedule_json(date: String) -> String { 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()
} }