Files
k-tv/crates/mcp/src/tools/channels.rs
Gabriel Kaszewski e2393be635 collapse 20 pass-through use cases; handlers call ports directly
delete get/list/list_by_owner channels, get_settings/activity_log admin,
get_item/get_sync_status/list_collections/list_seasons/list_shows/list_genres library,
get/list/delete providers, get/list/patch_label config_snapshots,
get_active/list_history/delete_after schedule — all single-delegation.

remove ChannelQueryDeps, LibraryQueryDeps, deleted query/command structs.
add direct port fields to AppState. update MCP crate accordingly.
2026-07-12 07:18:26 +02:00

87 lines
2.3 KiB
Rust

use std::sync::Arc;
use application::channels::{
ChannelCommandDeps, CreateChannelCommand, DeleteChannelCommand, UpdateChannelCommand,
};
use uuid::Uuid;
use crate::error::{domain_err, ok_json};
pub async fn list_channels(
channel_query: &Arc<dyn domain::ports::ChannelQuery>,
owner_id: Uuid,
) -> String {
match channel_query.find_by_owner(owner_id.into()).await {
Ok(channels) => ok_json(&channels),
Err(e) => domain_err(e),
}
}
pub async fn get_channel(
channel_query: &Arc<dyn domain::ports::ChannelQuery>,
id: Uuid,
) -> String {
match channel_query.find_by_id(id.into()).await {
Ok(Some(channel)) => ok_json(&channel),
Ok(None) => serde_json::json!({"error": "Channel not found"}).to_string(),
Err(e) => domain_err(e),
}
}
pub async fn create_channel(
cmd_deps: &Arc<ChannelCommandDeps>,
owner_id: Uuid,
name: &str,
timezone: &str,
) -> String {
let cmd = CreateChannelCommand {
owner_id: owner_id.into(),
name: name.to_string(),
timezone: timezone.to_string(),
};
match application::channels::create::execute(cmd_deps, cmd).await {
Ok(channel) => ok_json(&channel),
Err(e) => domain_err(e),
}
}
pub async fn update_channel(
cmd_deps: &Arc<ChannelCommandDeps>,
channel_id: Uuid,
owner_id: Uuid,
name: Option<String>,
timezone: Option<String>,
description: Option<String>,
schedule_config: Option<domain::ScheduleConfig>,
) -> String {
let cmd = UpdateChannelCommand {
channel_id: channel_id.into(),
owner_id: owner_id.into(),
name,
description: description.map(Some),
timezone,
schedule_config,
rotation_policy: None,
auto_schedule: None,
};
match application::channels::update::execute(cmd_deps, cmd).await {
Ok(channel) => ok_json(&channel),
Err(e) => domain_err(e),
}
}
pub async fn delete_channel(
cmd_deps: &Arc<ChannelCommandDeps>,
channel_id: Uuid,
owner_id: Uuid,
) -> String {
let cmd = DeleteChannelCommand {
channel_id: channel_id.into(),
owner_id: owner_id.into(),
};
match application::channels::delete::execute(cmd_deps, cmd).await {
Ok(()) => serde_json::json!({"deleted": channel_id}).to_string(),
Err(e) => domain_err(e),
}
}