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

@@ -1,6 +1,6 @@
use axum::Json;
use axum::extract::{Path, State};
use axum::http::StatusCode;
use axum::http::{StatusCode, header};
use axum::response::IntoResponse;
use chrono::Utc;
@@ -10,6 +10,7 @@ use api_types::{
use application::schedule::{
GenerateScheduleCommand, GetCurrentBroadcastQuery, GetEpgQuery, GetSourceQuery,
};
use domain::DomainError;
use domain::value_objects::ChannelId;
use crate::errors::AppError;
@@ -91,3 +92,26 @@ pub async fn list_schedule_history(
.collect(),
))
}
pub async fn export_ical(
State(state): State<AppState>,
Path(id): Path<uuid::Uuid>,
) -> Result<axum::response::Response, AppError> {
let channel = state
.channel_query
.find_by_id(id.into())
.await?
.ok_or_else(|| AppError(DomainError::NotFound(format!("Channel {id} not found"))))?;
let ical = domain::generate_ical(channel.name(), channel.timezone(), channel.schedule_config());
let disposition = format!("attachment; filename=\"{}.ics\"", channel.name());
Ok((
[
(header::CONTENT_TYPE, "text/calendar; charset=utf-8".to_string()),
(header::CONTENT_DISPOSITION, disposition),
],
ical,
)
.into_response())
}