mirror of https://github.com/buster-so/buster.git
version number added to get metric object
This commit is contained in:
parent
3baf029e11
commit
78ac791f83
|
@ -1,5 +1,6 @@
|
|||
use std::io::Write;
|
||||
|
||||
use chrono::{DateTime, Utc};
|
||||
use diesel::{
|
||||
deserialize::FromSql,
|
||||
pg::Pg,
|
||||
|
@ -18,6 +19,7 @@ pub struct VersionHistory(pub std::collections::HashMap<String, Version>);
|
|||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct Version {
|
||||
pub version_number: i32,
|
||||
pub updated_at: DateTime<Utc>,
|
||||
pub content: Value,
|
||||
}
|
||||
|
||||
|
@ -28,6 +30,7 @@ impl VersionHistory {
|
|||
Version {
|
||||
content,
|
||||
version_number,
|
||||
updated_at: Utc::now(),
|
||||
},
|
||||
)]))
|
||||
}
|
||||
|
@ -38,6 +41,7 @@ impl VersionHistory {
|
|||
Version {
|
||||
content,
|
||||
version_number,
|
||||
updated_at: Utc::now(),
|
||||
},
|
||||
);
|
||||
}
|
||||
|
|
|
@ -14,6 +14,8 @@ use database::enums::Verification;
|
|||
use database::pool::get_pg_pool;
|
||||
use database::schema::{datasets, metric_files};
|
||||
|
||||
use super::Version;
|
||||
|
||||
#[derive(Queryable, Selectable)]
|
||||
#[diesel(table_name = metric_files)]
|
||||
struct QueryableMetricFile {
|
||||
|
@ -154,6 +156,16 @@ pub async fn get_metric_handler(metric_id: &Uuid, user_id: &Uuid) -> Result<Bust
|
|||
// .await
|
||||
// .map_err(|e| anyhow!("Failed to get user information: {}", e))?;
|
||||
|
||||
let versions = metric_file
|
||||
.version_history
|
||||
.0
|
||||
.values()
|
||||
.map(|v| Version {
|
||||
version_number: v.version_number,
|
||||
updated_at: v.updated_at,
|
||||
})
|
||||
.collect();
|
||||
|
||||
// Construct BusterMetric
|
||||
Ok(BusterMetric {
|
||||
id: metric_file.id.to_string(),
|
||||
|
@ -180,6 +192,6 @@ pub async fn get_metric_handler(metric_id: &Uuid, user_id: &Uuid) -> Result<Bust
|
|||
code: None,
|
||||
dashboards: vec![], // TODO: Get associated dashboards
|
||||
collections: vec![], // TODO: Get associated collections
|
||||
versions: metric_file.version_history,
|
||||
versions,
|
||||
})
|
||||
}
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
use chrono::{DateTime, Utc};
|
||||
use database::{enums::Verification, types::VersionHistory};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::Value;
|
||||
|
@ -12,7 +13,7 @@ pub struct Dataset {
|
|||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct Version {
|
||||
pub version_number: i32,
|
||||
pub updated_at: String,
|
||||
pub updated_at: DateTime<Utc>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
|
@ -42,7 +43,7 @@ pub struct BusterMetric {
|
|||
pub code: Option<String>,
|
||||
pub dashboards: Vec<Dashboard>,
|
||||
pub collections: Vec<Collection>,
|
||||
pub versions: VersionHistory,
|
||||
pub versions: Vec<Version>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
|
|
Loading…
Reference in New Issue