mirror of https://github.com/buster-so/buster.git
74 lines
2.1 KiB
Rust
74 lines
2.1 KiB
Rust
use chrono::Utc;
|
|
use database::{
|
|
enums::Verification,
|
|
models::MetricFile,
|
|
types::{MetricYml, ChartConfig, VersionHistory}
|
|
};
|
|
use serde_json::Value;
|
|
use uuid::Uuid;
|
|
|
|
/// Creates a test metric file model
|
|
pub fn create_test_metric_file(
|
|
user_id: &Uuid,
|
|
org_id: &Uuid,
|
|
name: Option<String>,
|
|
) -> MetricFile {
|
|
let metric_name = name.unwrap_or_else(|| format!("Test Metric {}", Uuid::new_v4()));
|
|
|
|
// Create basic metric yaml content
|
|
let metric_yml = MetricYml {
|
|
description: Some("Test metric description".to_string()),
|
|
query: "SELECT * FROM test_table".to_string(),
|
|
chart_type: "bar".to_string(),
|
|
chart_config: ChartConfig::default(),
|
|
time_frame: "daily".to_string(),
|
|
dataset_ids: vec![Uuid::new_v4()],
|
|
};
|
|
|
|
// Create version history
|
|
let mut version_history = VersionHistory::default();
|
|
version_history.add_version(1, metric_yml.clone());
|
|
|
|
// Convert to JSON for storage
|
|
let content = serde_json::to_value(metric_yml).unwrap();
|
|
|
|
MetricFile {
|
|
id: Uuid::new_v4(),
|
|
name: metric_name,
|
|
content,
|
|
verification: Verification::Unverified,
|
|
created_at: Utc::now(),
|
|
updated_at: Utc::now(),
|
|
deleted_at: None,
|
|
created_by: *user_id,
|
|
updated_by: *user_id,
|
|
organization_id: *org_id,
|
|
version_history,
|
|
}
|
|
}
|
|
|
|
/// Creates update metric request data
|
|
pub fn create_update_metric_request() -> Value {
|
|
serde_json::json!({
|
|
"title": "Updated Test Metric",
|
|
"description": "Updated test description",
|
|
"chart_config": {
|
|
"xAxis": {
|
|
"title": "Updated X Axis"
|
|
},
|
|
"yAxis": {
|
|
"title": "Updated Y Axis"
|
|
}
|
|
},
|
|
"time_frame": "weekly",
|
|
"dataset_ids": [Uuid::new_v4().to_string()],
|
|
"verification": "verified"
|
|
})
|
|
}
|
|
|
|
/// Creates dashboard association request data
|
|
pub fn create_metric_dashboard_association_request(dashboard_id: &Uuid) -> Value {
|
|
serde_json::json!({
|
|
"dashboard_id": dashboard_id
|
|
})
|
|
} |