iCalendar export: domain service + API + MCP tool (#15)

This commit is contained in:
2026-07-12 14:27:20 +02:00
parent affd7f0223
commit b00272aceb
9 changed files with 315 additions and 3 deletions

View File

@@ -14,7 +14,7 @@ use schemars::JsonSchema;
use serde::Deserialize;
use uuid::Uuid;
use crate::tools::{channels, library, schedule};
use crate::tools::{channels, ical, library, schedule};
const SERVER_NAME: &str = "k-tv-mcp";
@@ -201,6 +201,16 @@ impl KTvMcpServer {
)
.await
}
#[tool(
description = "Export a channel's schedule as iCalendar (.ics). Returns RFC 5545 text."
)]
async fn export_schedule_ical(&self, #[tool(aggr)] p: ChannelIdParam) -> String {
match parse_uuid(&p.channel_id) {
Ok(id) => ical::export_schedule_ical(&self.channel_query, id).await,
Err(e) => e,
}
}
}
#[tool(tool_box)]

View File

@@ -0,0 +1,20 @@
use std::sync::Arc;
use uuid::Uuid;
use crate::error::domain_err;
pub async fn export_schedule_ical(
channel_query: &Arc<dyn domain::ports::ChannelQuery>,
channel_id: Uuid,
) -> String {
match channel_query.find_by_id(channel_id.into()).await {
Ok(Some(channel)) => domain::generate_ical(
channel.name(),
channel.timezone(),
channel.schedule_config(),
),
Ok(None) => serde_json::json!({"error": "Channel not found"}).to_string(),
Err(e) => domain_err(e),
}
}

View File

@@ -1,3 +1,4 @@
pub mod channels;
pub mod ical;
pub mod library;
pub mod schedule;