systemprompt_cli/commands/core/content/analytics/
journey.rs1use crate::cli_settings::CliConfig;
7use crate::commands::core::content::types::{JourneyNode, JourneyOutput};
8use crate::context::CommandContext;
9use crate::shared::CommandOutput;
10use anyhow::Result;
11use clap::Args;
12use systemprompt_content::LinkAnalyticsService;
13use systemprompt_database::DbPool;
14
15#[derive(Debug, Clone, Copy, Args)]
16pub struct JourneyArgs {
17 #[arg(long, default_value = "20")]
18 pub limit: i64,
19
20 #[arg(long, default_value = "0")]
21 pub offset: i64,
22}
23
24pub async fn execute(args: JourneyArgs, ctx: &CommandContext) -> Result<CommandOutput> {
25 execute_with_pool(args, &ctx.db_pool().await?, &ctx.cli).await
26}
27
28pub async fn execute_with_pool(
29 args: JourneyArgs,
30 pool: &DbPool,
31 _config: &CliConfig,
32) -> Result<CommandOutput> {
33 let service = LinkAnalyticsService::new(pool)?;
34
35 let nodes = service
36 .get_content_journey_map(Some(args.limit), Some(args.offset))
37 .await?;
38
39 let journey_nodes: Vec<JourneyNode> = nodes
40 .into_iter()
41 .map(|node| JourneyNode {
42 source_content_id: node.source_content_id,
43 target_url: node.target_url,
44 click_count: node.click_count,
45 })
46 .collect();
47
48 let output = JourneyOutput {
49 nodes: journey_nodes,
50 };
51
52 Ok(CommandOutput::table_of(
53 vec!["source_content_id", "target_url", "click_count"],
54 &output.nodes,
55 )
56 .with_title("Content Journey"))
57}