Skip to main content

systemprompt_cli/commands/core/content/link/
performance.rs

1use crate::cli_settings::CliConfig;
2use crate::commands::core::content::types::LinkPerformanceOutput;
3use crate::shared::CommandOutput;
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")]
13    pub link_id: String,
14}
15
16pub async fn execute(args: PerformanceArgs, _config: &CliConfig) -> Result<CommandOutput> {
17    let ctx = AppContext::new().await?;
18    let service = LinkAnalyticsService::new(ctx.db_pool())?;
19
20    let link_id = LinkId::new(args.link_id.clone());
21    let performance = service
22        .get_link_performance(&link_id)
23        .await?
24        .ok_or_else(|| anyhow!("Link not found: {}", args.link_id))?;
25
26    let output = LinkPerformanceOutput {
27        link_id: performance.link_id,
28        click_count: performance.click_count,
29        unique_click_count: performance.unique_click_count,
30        conversion_count: performance.conversion_count,
31        conversion_rate: performance.conversion_rate.unwrap_or(0.0),
32    };
33
34    Ok(CommandOutput::card_value("Link Performance", &output))
35}