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