version number added to get metric object

This commit is contained in:
dal 2025-03-11 16:06:07 -06:00
parent 3baf029e11
commit 78ac791f83
No known key found for this signature in database
GPG Key ID: 16F4B0E1E9F61122
3 changed files with 20 additions and 3 deletions

View File

@ -1,5 +1,6 @@
use std::io::Write; use std::io::Write;
use chrono::{DateTime, Utc};
use diesel::{ use diesel::{
deserialize::FromSql, deserialize::FromSql,
pg::Pg, pg::Pg,
@ -18,6 +19,7 @@ pub struct VersionHistory(pub std::collections::HashMap<String, Version>);
#[derive(Debug, Serialize, Deserialize, Clone)] #[derive(Debug, Serialize, Deserialize, Clone)]
pub struct Version { pub struct Version {
pub version_number: i32, pub version_number: i32,
pub updated_at: DateTime<Utc>,
pub content: Value, pub content: Value,
} }
@ -28,6 +30,7 @@ impl VersionHistory {
Version { Version {
content, content,
version_number, version_number,
updated_at: Utc::now(),
}, },
)])) )]))
} }
@ -38,6 +41,7 @@ impl VersionHistory {
Version { Version {
content, content,
version_number, version_number,
updated_at: Utc::now(),
}, },
); );
} }

View File

@ -14,6 +14,8 @@ use database::enums::Verification;
use database::pool::get_pg_pool; use database::pool::get_pg_pool;
use database::schema::{datasets, metric_files}; use database::schema::{datasets, metric_files};
use super::Version;
#[derive(Queryable, Selectable)] #[derive(Queryable, Selectable)]
#[diesel(table_name = metric_files)] #[diesel(table_name = metric_files)]
struct QueryableMetricFile { struct QueryableMetricFile {
@ -154,6 +156,16 @@ pub async fn get_metric_handler(metric_id: &Uuid, user_id: &Uuid) -> Result<Bust
// .await // .await
// .map_err(|e| anyhow!("Failed to get user information: {}", e))?; // .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 // Construct BusterMetric
Ok(BusterMetric { Ok(BusterMetric {
id: metric_file.id.to_string(), 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, code: None,
dashboards: vec![], // TODO: Get associated dashboards dashboards: vec![], // TODO: Get associated dashboards
collections: vec![], // TODO: Get associated collections collections: vec![], // TODO: Get associated collections
versions: metric_file.version_history, versions,
}) })
} }

View File

@ -1,3 +1,4 @@
use chrono::{DateTime, Utc};
use database::{enums::Verification, types::VersionHistory}; use database::{enums::Verification, types::VersionHistory};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use serde_json::Value; use serde_json::Value;
@ -12,7 +13,7 @@ pub struct Dataset {
#[derive(Debug, Serialize, Deserialize, Clone)] #[derive(Debug, Serialize, Deserialize, Clone)]
pub struct Version { pub struct Version {
pub version_number: i32, pub version_number: i32,
pub updated_at: String, pub updated_at: DateTime<Utc>,
} }
#[derive(Debug, Serialize, Deserialize, Clone)] #[derive(Debug, Serialize, Deserialize, Clone)]
@ -42,7 +43,7 @@ pub struct BusterMetric {
pub code: Option<String>, pub code: Option<String>,
pub dashboards: Vec<Dashboard>, pub dashboards: Vec<Dashboard>,
pub collections: Vec<Collection>, pub collections: Vec<Collection>,
pub versions: VersionHistory, pub versions: Vec<Version>,
} }
#[derive(Debug, Serialize, Deserialize, Clone)] #[derive(Debug, Serialize, Deserialize, Clone)]