diff --git a/api/libs/handlers/src/metrics/get_metric_data_handler.rs b/api/libs/handlers/src/metrics/get_metric_data_handler.rs index 0945cabc0..2a9341620 100644 --- a/api/libs/handlers/src/metrics/get_metric_data_handler.rs +++ b/api/libs/handlers/src/metrics/get_metric_data_handler.rs @@ -1,6 +1,5 @@ use agents::tools::file_tools::file_types::metric_yml::MetricYml; use anyhow::{anyhow, Result}; -use database::models::User; use indexmap::IndexMap; use serde::{Deserialize, Serialize}; use uuid::Uuid; @@ -41,7 +40,7 @@ pub async fn get_metric_data_handler( let metric = get_metric_handler(&request.metric_id, &user_id).await?; // Parse the metric definition from YAML to get SQL and dataset IDs - let metric_yml = serde_json::from_str::(&metric.file)?; + let metric_yml = serde_yaml::from_str::(&metric.file)?; let sql = metric_yml.sql; let dataset_ids = metric_yml.dataset_ids; diff --git a/api/libs/handlers/src/metrics/get_metric_handler.rs b/api/libs/handlers/src/metrics/get_metric_handler.rs index c50111c8c..521cdc5bc 100644 --- a/api/libs/handlers/src/metrics/get_metric_handler.rs +++ b/api/libs/handlers/src/metrics/get_metric_handler.rs @@ -147,12 +147,12 @@ pub async fn get_metric_handler(metric_id: &Uuid, user_id: &Uuid) -> Result(&mut conn) - .await - .map_err(|e| anyhow!("Failed to get user information: {}", e))?; + // let user_info = users::table + // .filter(users::id.eq(metric_file.created_by)) + // .select((users::name, users::avatar_url)) + // .first::(&mut conn) + // .await + // .map_err(|e| anyhow!("Failed to get user information: {}", e))?; // Construct BusterMetric Ok(BusterMetric { @@ -175,8 +175,8 @@ pub async fn get_metric_handler(metric_id: &Uuid, user_id: &Uuid) -> Result { + MetricRoute::Data => { let req = match serde_json::from_value(data) { Ok(req) => req, Err(e) => return Err(anyhow!("Error parsing request: {}", e)), @@ -56,7 +55,7 @@ impl MetricRoute { pub fn from_str(path: &str) -> Result { match path { "/metrics/get" => Ok(Self::Get), - "/metrics/get_data" => Ok(Self::GetData), + "/metrics/data" => Ok(Self::Data), _ => Err(anyhow!("Invalid path")), } } diff --git a/api/src/routes/ws/mod.rs b/api/src/routes/ws/mod.rs index 91f2608c3..cf488664c 100644 --- a/api/src/routes/ws/mod.rs +++ b/api/src/routes/ws/mod.rs @@ -8,6 +8,7 @@ mod search; mod sql; mod teams; mod terms; +mod metrics; pub mod threads_and_messages; mod users; pub mod ws; diff --git a/api/src/routes/ws/ws.rs b/api/src/routes/ws/ws.rs index 74e76da2f..38aec2c3d 100644 --- a/api/src/routes/ws/ws.rs +++ b/api/src/routes/ws/ws.rs @@ -33,20 +33,7 @@ use uuid::Uuid; use middleware::AuthenticatedUser; use super::{ - collections::collections_router::CollectionEvent, - dashboards::dashboards_router::DashboardEvent, - data_sources::data_sources_router::DataSourceEvent, - datasets::datasets_router::DatasetEvent, - organizations::organization_router::OrganizationEvent, - permissions::permissions_router::PermissionEvent, - search::search_router::SearchEvent, - sql::sql_router::SqlEvent, - teams::teams_routes::TeamEvent, - terms::terms_router::TermEvent, - threads_and_messages::threads_router::ThreadEvent, - users::users_router::UserEvent, - ws_router::{ws_router, WsRoutes}, - ws_utils::{subscribe_to_stream, unsubscribe_from_stream}, + collections::collections_router::CollectionEvent, dashboards::dashboards_router::DashboardEvent, data_sources::data_sources_router::DataSourceEvent, datasets::datasets_router::DatasetEvent, metrics::MetricEvent, organizations::organization_router::OrganizationEvent, permissions::permissions_router::PermissionEvent, search::search_router::SearchEvent, sql::sql_router::SqlEvent, teams::teams_routes::TeamEvent, terms::terms_router::TermEvent, threads_and_messages::threads_router::ThreadEvent, users::users_router::UserEvent, ws_router::{ws_router, WsRoutes}, ws_utils::{subscribe_to_stream, unsubscribe_from_stream} }; const CLIENT_TIMEOUT: Duration = Duration::from_secs(300); @@ -74,6 +61,7 @@ pub enum WsEvent { Terms(TermEvent), Search(SearchEvent), Organizations(OrganizationEvent), + Metrics(MetricEvent), } #[derive(Serialize, Deserialize, Clone)] diff --git a/api/src/routes/ws/ws_router.rs b/api/src/routes/ws/ws_router.rs index 04b2d0a94..973cc05d5 100644 --- a/api/src/routes/ws/ws_router.rs +++ b/api/src/routes/ws/ws_router.rs @@ -11,19 +11,7 @@ use crate::routes::ws::{ }; use super::{ - collections::collections_router::{collections_router, CollectionRoute}, - dashboards::dashboards_router::DashboardRoute, - data_sources::data_sources_router::{data_sources_router, DataSourceRoute}, - datasets::datasets_router::DatasetRoute, - organizations::organization_router::{organizations_router, OrganizationRoute}, - permissions::permissions_router::{permissions_router, PermissionRoute}, - search::search_router::{search_router, SearchRoute}, - sql::sql_router::{sql_router, SqlRoute}, - teams::teams_routes::{teams_router, TeamRoute}, - terms::terms_router::{terms_router, TermRoute}, - threads_and_messages::threads_router::{threads_router, ThreadRoute}, - users::users_router::{users_router, UserRoute}, - ws::SubscriptionRwLock, + collections::collections_router::{collections_router, CollectionRoute}, dashboards::dashboards_router::DashboardRoute, data_sources::data_sources_router::{data_sources_router, DataSourceRoute}, datasets::datasets_router::DatasetRoute, metrics::{metrics_router, MetricRoute}, organizations::organization_router::{organizations_router, OrganizationRoute}, permissions::permissions_router::{permissions_router, PermissionRoute}, search::search_router::{search_router, SearchRoute}, sql::sql_router::{sql_router, SqlRoute}, teams::teams_routes::{teams_router, TeamRoute}, terms::terms_router::{terms_router, TermRoute}, threads_and_messages::threads_router::{threads_router, ThreadRoute}, users::users_router::{users_router, UserRoute}, ws::SubscriptionRwLock }; #[derive(Deserialize, Serialize, Debug, Clone)] @@ -41,6 +29,7 @@ pub enum WsRoutes { Terms(TermRoute), Search(SearchRoute), Organizations(OrganizationRoute), + Metrics(MetricRoute), } impl WsRoutes { @@ -63,6 +52,7 @@ impl WsRoutes { "terms" => Ok(Self::Terms(TermRoute::from_str(path)?)), "search" => Ok(Self::Search(SearchRoute::from_str(path)?)), "organizations" => Ok(Self::Organizations(OrganizationRoute::from_str(path)?)), + "metrics" => Ok(Self::Metrics(MetricRoute::from_str(path)?)), _ => Err(anyhow!("Invalid path")), } } @@ -107,6 +97,7 @@ pub async fn ws_router( WsRoutes::Organizations(organizations_route) => { organizations_router(organizations_route, payload, user).await } + WsRoutes::Metrics(metrics_route) => metrics_router(metrics_route, payload, user).await, }; if let Err(e) = result {