@@ -2,6 +2,7 @@ use crate::{
22 handlers:: http:: ingest:: PostError ,
33 option:: CONFIG ,
44 storage:: { object_storage:: dashboard_path, ObjectStorageError } ,
5+ users:: dashboards:: { Dashboard , DASHBOARDS } ,
56} ;
67use actix_web:: { http:: header:: ContentType , web, HttpRequest , HttpResponse , Responder } ;
78use bytes:: Bytes ;
@@ -44,13 +45,18 @@ pub async fn get(req: HttpRequest) -> Result<impl Responder, DashboardError> {
4445 . get ( "dashboard_id" )
4546 . ok_or ( DashboardError :: Metadata ( "No Dashboard Id Provided" ) ) ?;
4647
48+ if let Some ( dashboard) = DASHBOARDS . find ( dash_id) {
49+ return Ok ( ( web:: Json ( dashboard) , StatusCode :: OK ) ) ;
50+ }
51+
52+ //if dashboard is not in memory fetch from s3
4753 let dash_file_path = dashboard_path ( user_id, & format ! ( "{}.json" , dash_id) ) ;
4854 let resource = CONFIG
4955 . storage ( )
5056 . get_object_store ( )
5157 . get_object ( & dash_file_path)
5258 . await ?;
53- let resource = serde_json:: from_slice :: < JsonValue > ( & resource) ?;
59+ let resource = serde_json:: from_slice :: < Dashboard > ( & resource) ?;
5460
5561 Ok ( ( web:: Json ( resource) , StatusCode :: OK ) )
5662}
@@ -68,6 +74,9 @@ pub async fn post(req: HttpRequest, body: Bytes) -> Result<HttpResponse, PostErr
6874
6975 let dash_file_path = dashboard_path ( user_id, & format ! ( "{}.json" , dash_id) ) ;
7076
77+ let dashboard = serde_json:: from_slice :: < Dashboard > ( & body) ?;
78+ DASHBOARDS . update ( dashboard) ;
79+
7180 let store = CONFIG . storage ( ) . get_object_store ( ) ;
7281 store. put_object ( & dash_file_path, body) . await ?;
7382
@@ -93,32 +102,6 @@ pub async fn delete(req: HttpRequest) -> Result<HttpResponse, PostError> {
93102 Ok ( HttpResponse :: Ok ( ) . finish ( ) )
94103}
95104
96- // #[derive(Debug, Serialize, Deserialize)]
97- // pub struct Dashboard {
98- // version: String,
99- // name: String,
100- // id: String,
101- // time_filter: TimeFilter
102- // refresh_interval: u64,
103- // pannels: Vec<Pannel>,
104- // }
105- //
106- // #[derive(Debug, Serialize, Deserialize)]
107- // pub struct Pannel {
108- // stream_name: String,
109- // query: String,
110- // chart_type: String,
111- // columns: Vec<String>,
112- // headers: Vec<String>,
113- // dimensions: (u64, u64),
114- // }
115- //
116- // #[derive(Debug, Serialize, Deserialize)]
117- // pub struct TimeFilter {
118- // to: String,
119- // from: String
120- // }
121-
122105#[ derive( Debug , thiserror:: Error ) ]
123106pub enum DashboardError {
124107 #[ error( "Failed to connect to storage: {0}" ) ]
0 commit comments