use chrono::Utc; use domain::models::ScheduledSlot; use domain::value_objects::ChannelId; use domain::{DomainResult, ScheduleEngineService}; use super::deps::ScheduleDeps; use super::queries::GetEpgQuery; /// Return EPG (electronic program guide) data for a channel. /// /// Returns the slots that overlap the active schedule's validity window. /// Returns an empty vec when no schedule is active. pub async fn execute( deps: &ScheduleDeps, query: GetEpgQuery, ) -> DomainResult> { let channel_id = ChannelId::from(query.channel_id); let now = Utc::now(); let schedule = match deps.schedule_query.find_active(channel_id, now).await? { Some(s) => s, None => return Ok(vec![]), }; let slots = ScheduleEngineService::get_epg( &schedule, schedule.valid_from(), schedule.valid_until(), ); Ok(slots.into_iter().cloned().collect()) } #[cfg(test)] #[path = "tests/get_epg.rs"] mod tests;