Skip to main content

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

1//! `core content link performance` command.
2//!
3//! Copyright (c) systemprompt.io — Business Source License 1.1.
4//! See <https://systemprompt.io> for licensing details.
5
6use crate::commands::core::content::types::LinkPerformanceOutput;
7use crate::context::CommandContext;
8use crate::shared::CommandOutput;
9use anyhow::{Result, anyhow};
10use clap::Args;
11use systemprompt_content::LinkAnalyticsService;
12use systemprompt_identifiers::LinkId;
13
14#[derive(Debug, Args)]
15pub struct PerformanceArgs {
16    #[arg(help = "Link ID")]
17    pub link_id: String,
18}
19
20pub async fn execute(args: PerformanceArgs, ctx: &CommandContext) -> Result<CommandOutput> {
21    let pool = ctx.db_pool().await?;
22    let service = LinkAnalyticsService::new(&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(CommandOutput::card_value("Link Performance", &output))
39}