church-core/src/uniffi/sermons.rs
Benjamin Slingo f04644856b Fix compilation errors and complete modular refactoring
Major changes:
• Remove Android support completely (deleted bindings/android/)
• Modularize uniffi_wrapper.rs (1,756→5 lines, split into focused modules)
• Reduce DRY violations in api.rs (620→292 lines)
• Fix all 20+ compilation errors to achieve clean build

Structural improvements:
• Split uniffi_wrapper into specialized modules: events, sermons, bible, contact, config, streaming, parsing
• Clean up dependencies (remove unused Android/JNI deps)
• Consolidate duplicate API functions
• Standardize error handling and validation

Bug fixes:
• Add missing ClientEvent fields (image_url, is_upcoming, is_today)
• Fix method name mismatches (update_bulletin→update_admin_bulletin)
• Correct ValidationResult struct (use errors field)
• Resolve async/await issues in bible.rs
• Fix event conversion type mismatches
• Add missing EventSubmission.image_mime_type field

The codebase now compiles cleanly with only warnings and is ready for further modular improvements.
2025-08-30 16:49:35 -04:00

49 lines
1.9 KiB
Rust

use crate::{ChurchApiClient, ClientSermon, Sermon};
use std::sync::Arc;
// Shared helper function to convert Sermon objects to JSON with proper formatting
fn sermons_to_json(sermons: Vec<Sermon>, content_type: &str, base_url: &str) -> String {
let client_sermons: Vec<ClientSermon> = sermons
.iter()
.map(|sermon| ClientSermon::from_sermon_with_base_url(sermon.clone(), base_url))
.collect();
serde_json::to_string(&client_sermons).unwrap_or_else(|_| "[]".to_string())
}
pub fn fetch_sermons_json() -> String {
let client = super::get_or_create_client();
let rt = super::get_runtime();
match rt.block_on(async { client.get_sermons(None).await }) {
Ok(response) => sermons_to_json(response.data.items, "videos", "https://church.adventist.app"),
Err(_) => "[]".to_string(),
}
}
pub fn parse_sermons_from_json(sermons_json: String) -> String {
match serde_json::from_str::<Vec<Sermon>>(&sermons_json) {
Ok(sermons) => sermons_to_json(sermons, "videos", "https://church.adventist.app"),
Err(_) => "[]".to_string(),
}
}
pub fn filter_sermons_by_media_type(sermons_json: String, media_type_str: String) -> String {
match serde_json::from_str::<Vec<Sermon>>(&sermons_json) {
Ok(sermons) => {
let filtered_sermons: Vec<Sermon> = sermons.into_iter()
.filter(|sermon| {
match media_type_str.to_lowercase().as_str() {
"video" => sermon.video_url.is_some(),
"audio" => sermon.audio_url.is_some(),
"both" => sermon.video_url.is_some() && sermon.audio_url.is_some(),
_ => true, // Return all sermons for unknown types
}
})
.collect();
sermons_to_json(filtered_sermons, "videos", "https://church.adventist.app")
},
Err(_) => "[]".to_string(),
}
}