systemprompt_cli/commands/core/content/link/
performance.rs1use 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 repositories = ctx.app_context().await?.content_repositories();
22 let service = LinkAnalyticsService::new(
23 repositories.link.clone(),
24 repositories.link_analytics.clone(),
25 );
26
27 let link_id = LinkId::new(args.link_id.clone());
28 let performance = service
29 .get_link_performance(&link_id)
30 .await?
31 .ok_or_else(|| anyhow!("Link not found: {}", args.link_id))?;
32
33 let output = LinkPerformanceOutput {
34 link_id: performance.link_id,
35 click_count: performance.click_count,
36 unique_click_count: performance.unique_click_count,
37 conversion_count: performance.conversion_count,
38 conversion_rate: performance.conversion_rate.unwrap_or(0.0),
39 };
40
41 Ok(CommandOutput::card_value("Link Performance", &output))
42}