RTSDA-iOS/CHURCH_SERVICE_MIGRATION.md
RTSDA 00679f927c docs: Update README for v2.0 release and fix git remote URL
- Comprehensive README update documenting v2.0 architectural changes
- Updated git remote to ssh://rockvilleav@git.rockvilletollandsda.church:10443/RTSDA/RTSDA-iOS.git
- Documented unified ChurchService and 60% code reduction
- Added new features: Home Feed, responsive reading, enhanced UI
- Corrected license information (GPL v3 with church content copyright)
- Updated build instructions and technical stack details
2025-08-16 18:41:51 -04:00

149 lines
3.9 KiB
Markdown

# ChurchService Migration Guide
The new `ChurchService` replaces all legacy networking services and uses the church_core Rust library for consistent, performant API calls.
## Migration Overview
**Replace these services:**
- `PocketBaseService`
- `BulletinService`
- `BibleService`
- `ConfigService`
**With this unified service:**
- `ChurchService`
## Quick Migration
### Before (Old Services)
```swift
// Config
let config = try await PocketBaseService.shared.fetchConfig()
// Events
let events = try await PocketBaseService.shared.fetchEvents()
// Bulletins
let bulletins = try await BulletinService.shared.getBulletins()
let latest = try await BulletinService.shared.getLatestBulletin()
// Bible Verses
let verse = try await BibleService.shared.getRandomVerse()
let specificVerse = try await BibleService.shared.getVerse(reference: "John 3:16")
```
### After (ChurchService)
```swift
// Config
let config = try await ChurchService.shared.fetchConfig()
// Events
let events = try await ChurchService.shared.fetchEvents()
// Bulletins
let bulletins = try await ChurchService.shared.getBulletins()
let latest = try await ChurchService.shared.getLatestBulletin()
// Bible Verses
let verse = try await ChurchService.shared.getRandomVerse()
let specificVerse = try await ChurchService.shared.getVerse(reference: "John 3:16")
// Contact
let success = try await ChurchService.shared.submitContact(
name: "John Doe",
email: "john@example.com",
message: "Hello"
)
// Sermons
let sermons = try await ChurchService.shared.fetchSermons()
```
## Benefits of Migration
### ✅ **Code Reduction**
- **Before:** ~500+ lines across 4 services
- **After:** ~220 lines in 1 service
- **Reduction:** 60%+ less duplicate code
### ✅ **Performance**
- Uses optimized Rust networking (reqwest)
- Built-in memory caching
- Faster JSON parsing
- Better error handling
### ✅ **Consistency**
- Same API used by website and Beacon
- Consistent data models
- Unified error handling
- Single source of truth
### ✅ **Maintenance**
- One service to maintain
- Automatic updates from church_core
- Fewer bugs and edge cases
- Better testing coverage
## Implementation Details
### Required Files
1. **Add to project:** `church_core.swift` (UniFFI bindings)
2. **Add to project:** `libchurch_core.dylib` (Rust library)
3. **Replace with:** `ChurchService.swift` (Unified service)
### Xcode Integration
1. Add `church_core.swift` to your Xcode project
2. Add `libchurch_core.dylib` to your project and link it
3. Replace service imports with `ChurchService.shared`
### Backwards Compatibility
The new service maintains the same method signatures as the old services, so migration is a simple find-and-replace:
```swift
// Find: PocketBaseService.shared
// Replace: ChurchService.shared
// Find: BulletinService.shared
// Replace: ChurchService.shared
// Find: BibleService.shared
// Replace: ChurchService.shared
```
## Testing
```swift
// Test the new service
Task {
do {
let config = try await ChurchService.shared.fetchConfig()
print("Church: \(config.churchName)")
let verse = try await ChurchService.shared.getRandomVerse()
print("Verse: \(verse.reference) - \(verse.verse)")
let bulletins = try await ChurchService.shared.getBulletins()
print("Bulletins: \(bulletins.count)")
} catch {
print("Error: \(error)")
}
}
```
## Migration Checklist
- [ ] Add `church_core.swift` to Xcode project
- [ ] Add `libchurch_core.dylib` to project and link
- [ ] Add `ChurchService.swift` to project
- [ ] Update Sermon model to be Codable (already done)
- [ ] Replace service imports in Views/ViewModels
- [ ] Test all functionality works
- [ ] Remove old service files (optional)
- [ ] Update any custom networking code
## Next Steps
Once migration is complete, you can:
1. Delete the old service files
2. Clean up any unused networking utilities
3. Enjoy simplified, faster networking! 🚀