Skip to content

Commit 9aaa2cc

Browse files
update: dashboard APIs (#865)
1. remove stream field from tile struct 2. rename y_key to y_keys in graph config 3. fix to generate tile_id for each tile in POST /dashboards 4. fix to generate tile_id for new tiles where tile_id is not present in the request in the PUT /dashboards/dashboard/<dashboard-id> 5. return dashboard json in PUT response
1 parent 0325d1b commit 9aaa2cc

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

server/src/handlers/http/users/dashboards.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,14 @@ pub async fn post(body: Bytes) -> Result<impl Responder, PostError> {
5757
let dashboard_id = format!("{}.{}", &dashboard.user_id, Utc::now().timestamp_millis());
5858
dashboard.dashboard_id = Some(dashboard_id.clone());
5959
dashboard.version = Some(CURRENT_DASHBOARD_VERSION.to_string());
60-
DASHBOARDS.update(&dashboard);
6160
for tile in dashboard.tiles.iter_mut() {
6261
tile.tile_id = Some(format!(
6362
"{}.{}",
6463
&dashboard.user_id,
6564
Utc::now().timestamp_micros()
6665
));
6766
}
67+
DASHBOARDS.update(&dashboard);
6868

6969
let path = dashboard_path(&dashboard.user_id, &format!("{}.json", dashboard_id));
7070

@@ -77,7 +77,7 @@ pub async fn post(body: Bytes) -> Result<impl Responder, PostError> {
7777
Ok((web::Json(dashboard), StatusCode::OK))
7878
}
7979

80-
pub async fn update(req: HttpRequest, body: Bytes) -> Result<HttpResponse, PostError> {
80+
pub async fn update(req: HttpRequest, body: Bytes) -> Result<impl Responder, PostError> {
8181
let dashboard_id = req
8282
.match_info()
8383
.get("dashboard_id")
@@ -90,6 +90,15 @@ pub async fn update(req: HttpRequest, body: Bytes) -> Result<HttpResponse, PostE
9090
let mut dashboard: Dashboard = serde_json::from_slice(&body)?;
9191
dashboard.dashboard_id = Some(dashboard_id.to_string());
9292
dashboard.version = Some(CURRENT_DASHBOARD_VERSION.to_string());
93+
for tile in dashboard.tiles.iter_mut() {
94+
if tile.tile_id.is_none() {
95+
tile.tile_id = Some(format!(
96+
"{}.{}",
97+
&dashboard.user_id,
98+
Utc::now().timestamp_micros()
99+
));
100+
}
101+
}
93102
DASHBOARDS.update(&dashboard);
94103

95104
let path = dashboard_path(&dashboard.user_id, &format!("{}.json", dashboard_id));
@@ -100,7 +109,7 @@ pub async fn update(req: HttpRequest, body: Bytes) -> Result<HttpResponse, PostE
100109
.put_object(&path, Bytes::from(dashboard_bytes))
101110
.await?;
102111

103-
Ok(HttpResponse::Ok().finish())
112+
Ok((web::Json(dashboard), StatusCode::OK))
104113
}
105114

106115
pub async fn delete(req: HttpRequest) -> Result<HttpResponse, PostError> {

server/src/users/dashboards.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ pub struct Tiles {
3333
name: String,
3434
pub tile_id: Option<String>,
3535
description: String,
36-
stream: String,
3736
query: String,
3837
order: Option<u64>,
3938
visualization: Visualization,
@@ -57,7 +56,7 @@ pub struct CircularChartConfig {
5756
#[derive(Debug, Serialize, Deserialize, Default, Clone)]
5857
pub struct GraphConfig {
5958
x_key: String,
60-
y_key: Vec<String>,
59+
y_keys: Vec<String>,
6160
}
6261

6362
#[derive(Debug, Serialize, Deserialize, Default, Clone)]

0 commit comments

Comments
 (0)