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::{anyhow, Result};
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(
17 args: PerformanceArgs,
18 _config: &CliConfig,
19) -> Result<CommandResult<LinkPerformanceOutput>> {
20 let ctx = AppContext::new().await?;
21 let service = LinkAnalyticsService::new(ctx.db_pool())?;
22
23 let link_id = LinkId::new(args.link_id.clone());
24 let performance = service
25 .get_link_performance(&link_id)
26 .await?
27 .ok_or_else(|| anyhow!("Link not found: {}", args.link_id))?;
28
29 let output = LinkPerformanceOutput {
30 link_id: performance.link_id,
31 click_count: performance.click_count,
32 unique_click_count: performance.unique_click_count,
33 conversion_count: performance.conversion_count,
34 conversion_rate: performance.conversion_rate.unwrap_or(0.0),
35 };
36
37 Ok(CommandResult::card(output).with_title("Link Performance"))
38}