mcp: MCP server calling application use cases
This commit is contained in:
86
crates/mcp/src/tools/channels.rs
Normal file
86
crates/mcp/src/tools/channels.rs
Normal file
@@ -0,0 +1,86 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use application::channels::{
|
||||
ChannelCommandDeps, ChannelQueryDeps, CreateChannelCommand, DeleteChannelCommand,
|
||||
GetChannelQuery, ListByOwnerQuery, UpdateChannelCommand,
|
||||
};
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::error::{domain_err, ok_json};
|
||||
|
||||
pub async fn list_channels(
|
||||
query_deps: &Arc<ChannelQueryDeps>,
|
||||
owner_id: Uuid,
|
||||
) -> String {
|
||||
let query = ListByOwnerQuery { owner_id };
|
||||
match application::channels::list_by_owner::execute(query_deps, query).await {
|
||||
Ok(channels) => ok_json(&channels),
|
||||
Err(e) => domain_err(e),
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn get_channel(query_deps: &Arc<ChannelQueryDeps>, id: Uuid) -> String {
|
||||
let query = GetChannelQuery { channel_id: id };
|
||||
match application::channels::get::execute(query_deps, query).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,
|
||||
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,
|
||||
owner_id,
|
||||
name,
|
||||
description: description.map(Some),
|
||||
timezone,
|
||||
schedule_config,
|
||||
recycle_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,
|
||||
owner_id,
|
||||
};
|
||||
match application::channels::delete::execute(cmd_deps, cmd).await {
|
||||
Ok(()) => serde_json::json!({"deleted": channel_id}).to_string(),
|
||||
Err(e) => domain_err(e),
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user