iCalendar export: domain service + API + MCP tool (#15)
This commit is contained in:
@@ -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())
|
||||
}
|
||||
|
||||
@@ -44,6 +44,7 @@ fn channel_router() -> Router<AppState> {
|
||||
.route("/{id}/now", get(handlers::schedule::get_current_broadcast))
|
||||
.route("/{id}/epg", get(handlers::schedule::get_epg))
|
||||
.route("/{id}/stream", get(handlers::schedule::get_stream))
|
||||
.route("/{id}/export.ics", get(handlers::schedule::export_ical))
|
||||
.route("/{id}/snapshots", post(handlers::channels::save_snapshot))
|
||||
.route("/{id}/snapshots", get(handlers::channels::list_snapshots))
|
||||
.route("/{id}/snapshots/{snapshot_id}", get(handlers::channels::get_snapshot))
|
||||
|
||||
Reference in New Issue
Block a user