feat(mcp): implement media channel management and scheduling features
This commit is contained in:
47
k-tv-backend/mcp/src/tools/schedule.rs
Normal file
47
k-tv-backend/mcp/src/tools/schedule.rs
Normal file
@@ -0,0 +1,47 @@
|
||||
use chrono::Utc;
|
||||
use domain::{ScheduleEngineService, ScheduledSlot};
|
||||
use serde::Serialize;
|
||||
use std::sync::Arc;
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::error::{domain_err, ok_json};
|
||||
|
||||
/// Serializable DTO for CurrentBroadcast (domain type does not derive Serialize).
|
||||
#[derive(Serialize)]
|
||||
struct CurrentBroadcastDto {
|
||||
slot: ScheduledSlot,
|
||||
offset_secs: u32,
|
||||
}
|
||||
|
||||
pub async fn generate_schedule(engine: &Arc<ScheduleEngineService>, channel_id: Uuid) -> String {
|
||||
match engine.generate_schedule(channel_id, Utc::now()).await {
|
||||
Ok(schedule) => ok_json(&schedule),
|
||||
Err(e) => domain_err(e),
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn get_active_schedule(engine: &Arc<ScheduleEngineService>, channel_id: Uuid) -> String {
|
||||
match engine.get_active_schedule(channel_id, Utc::now()).await {
|
||||
Ok(Some(schedule)) => ok_json(&schedule),
|
||||
Ok(None) => "null".to_string(),
|
||||
Err(e) => domain_err(e),
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn get_current_broadcast(
|
||||
engine: &Arc<ScheduleEngineService>,
|
||||
channel_id: Uuid,
|
||||
) -> String {
|
||||
let schedule = match engine.get_active_schedule(channel_id, Utc::now()).await {
|
||||
Ok(Some(s)) => s,
|
||||
Ok(None) => return "null".to_string(),
|
||||
Err(e) => return domain_err(e),
|
||||
};
|
||||
match ScheduleEngineService::get_current_broadcast(&schedule, Utc::now()) {
|
||||
Some(b) => ok_json(&CurrentBroadcastDto {
|
||||
slot: b.slot,
|
||||
offset_secs: b.offset_secs,
|
||||
}),
|
||||
None => "null".to_string(),
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user