systemprompt_cli/commands/core/content/link/
performance.rs1use crate::cli_settings::CliConfig;
2use crate::commands::core::content::types::LinkPerformanceOutput;
3use crate::shared::CommandResult;
4use anyhow::{Result, anyhow};
5use clap::Args;
6use systemprompt_content::LinkAnalyticsService;
7use systemprompt_identifiers::LinkId;
8use systemprompt_runtime::AppContext;
9
10#[derive(Debug, Args)]
11pub struct PerformanceArgs {
12 #[arg(help = "Link ID")]
14 pub link_id: String,
15}
16
17pub async fn execute(
18 args: PerformanceArgs,
19 _config: &CliConfig,
20) -> Result<CommandResult<LinkPerformanceOutput>> {
21 let ctx = AppContext::new().await?;
22 let service = LinkAnalyticsService::new(ctx.db_pool())?;
23
24 let link_id = LinkId::new(args.link_id.clone());
25 let performance = service
26 .get_link_performance(&link_id)
27 .await?
28 .ok_or_else(|| anyhow!("Link not found: {}", args.link_id))?;
29
30 let output = LinkPerformanceOutput {
31 link_id: performance.link_id,
32 click_count: performance.click_count,
33 unique_click_count: performance.unique_click_count,
34 conversion_count: performance.conversion_count,
35 conversion_rate: performance.conversion_rate.unwrap_or(0.0),
36 };
37
38 Ok(CommandResult::card(output).with_title("Link Performance"))
39}