application: schedule bounded context

This commit is contained in:
2026-07-12 02:02:23 +02:00
parent 6fd47f2d93
commit ef86a967cd
21 changed files with 608 additions and 0 deletions

View File

@@ -0,0 +1,37 @@
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<Vec<ScheduledSlot>> {
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;