
Complete church management system with bulletin management, media processing, live streaming integration, and web interface. Includes authentication, email notifications, database migrations, and comprehensive test suite.
5.9 KiB
5.9 KiB
Next Steps for Service Layer Migration
Immediate Actions Required
1. Clean Up Current EventService Import
# Remove unused import from events service
# File: src/services/events.rs line 10
# Remove: db_operations::EventOperations,
2. Migrate Remaining Modules (In Priority Order)
A. Bulletins Service (HIGH PRIORITY)
Files to create:
// src/services/bulletins.rs
pub struct BulletinService;
impl BulletinService {
pub async fn create_v1(pool: &PgPool, req: CreateBulletinRequest, url_builder: &UrlBuilder) -> Result<Bulletin> {
let bulletin = db::bulletins::create(pool, req).await?;
convert_bulletin_to_v1(bulletin, url_builder)
}
pub async fn update_v1(pool: &PgPool, id: &Uuid, req: UpdateBulletinRequest, url_builder: &UrlBuilder) -> Result<Bulletin> {
let bulletin = db::bulletins::update(pool, id, req).await?;
convert_bulletin_to_v1(bulletin, url_builder)
}
// Add V2 methods with timezone flexibility
}
Files to modify:
src/handlers/bulletins.rs
- Replace direct db calls with BulletinService callssrc/handlers/v2/bulletins.rs
- Replace direct db calls with BulletinService callssrc/services/mod.rs
- Addpub mod bulletins;
andpub use bulletins::BulletinService;
B. Users/Auth Service (HIGH PRIORITY)
Files to create:
// src/services/auth.rs
pub struct AuthService;
impl AuthService {
pub async fn authenticate_user(pool: &PgPool, username: &str, password: &str) -> Result<User> {
let user = db::users::get_by_username(pool, username).await?
.ok_or_else(|| ApiError::Unauthorized("Invalid credentials".to_string()))?;
let password_hash = db::users::get_password_hash(pool, &user.id).await?;
// Verify password logic here
// Return user with V1 timezone conversion if needed
}
pub async fn get_user_by_id(pool: &PgPool, id: &Uuid) -> Result<Option<User>> {
db::users::get_by_id(pool, id).await
}
}
Files to modify:
src/handlers/auth.rs
- Replace direct db calls with AuthService calls
C. Bible Verses Service
Files to create:
// src/services/bible_verses.rs
pub struct BibleVerseService;
impl BibleVerseService {
pub async fn get_random_v1(pool: &PgPool) -> Result<Option<BibleVerse>> {
let verse = BibleVerseOperations::get_random(pool).await?;
// Apply V1 timezone conversion if needed
}
pub async fn search_v1(pool: &PgPool, query: &str, limit: i64) -> Result<Vec<BibleVerse>> {
let verses = BibleVerseOperations::search(pool, query, limit).await?;
// Apply V1 timezone conversion if needed
}
}
D. Schedule Service
Files to create:
// src/services/schedule.rs
pub struct ScheduleService;
impl ScheduleService {
pub async fn get_by_date_v1(pool: &PgPool, date: NaiveDate) -> Result<Option<Schedule>> {
ScheduleOperations::get_by_date(pool, date).await
}
pub async fn get_for_range_v1(pool: &PgPool, start: NaiveDate, end: NaiveDate) -> Result<Vec<Schedule>> {
ScheduleOperations::get_for_range(pool, start, end).await
}
}
E. Config Service (LOW PRIORITY)
Files to create:
// src/services/config.rs
pub struct ConfigService;
impl ConfigService {
pub async fn update_config(pool: &PgPool, config: ChurchConfig) -> Result<ChurchConfig> {
// Add business logic validation here
db::config::update_config(pool, config).await
}
}
Migration Checklist Template
For each module, follow this checklist:
Service Creation
- Create
src/services/{module}.rs
- Implement
{Module}Service
struct - Add V1 methods that call
db::{module}::*
functions - Add V2 methods with timezone flexibility
- Apply proper timezone conversions and URL building
Handler Migration
- Update imports to use service instead of direct db calls
- Replace
db::{module}::*
calls with{Module}Service::*
calls - Ensure handlers stay thin (no business logic)
- Test that all endpoints still work
Module Registration
- Add
pub mod {module};
tosrc/services/mod.rs
- Add
pub use {module}::{Module}Service;
tosrc/services/mod.rs
Verification
- Run
cargo build
and confirm specific "unused" warnings eliminated - Test API endpoints to ensure functionality preserved
- Verify timezone conversion working correctly
Expected Results After Full Migration
Warning Reduction
- Current: 64 warnings
- Target: ~45-50 warnings
- Eliminated: ~15-20 legitimate "unused function" warnings
Architecture Achieved
- Thin handlers - HTTP concerns only
- Service layer - All business logic centralized
- Database layer - Data access properly abstracted
- Dumb frontend - No logic, just displays backend data
Maintainability Gains
- Business logic changes only require service layer updates
- Easy to add caching, validation, authorization at service level
- Clear separation of concerns
- Better testability
Files That Will Remain "Unused" (Legitimate)
These are utility functions for future features and can be ignored:
src/utils/response.rs
helper functionssrc/utils/database.rs
generic utilitiessrc/utils/datetime.rs
display formatting functionssrc/utils/validation.rs
optional validation methodssrc/utils/handlers.rs
generic handler utilities- Model structs for future API versions
Timeline Estimate
- Bulletins: 30 minutes
- Users/Auth: 45 minutes
- Bible Verses: 20 minutes
- Schedule: 20 minutes
- Config: 15 minutes
- Total: ~2.5 hours
Success Criteria
- All database functions showing "unused" warnings are eliminated
- Application builds and runs without breaking changes
- API endpoints continue to work exactly as before
- Service layer properly centralizes business logic
- Handlers are thin and focused on HTTP concerns only