Skip to content

Commit be5396d

Browse files
authored
Add resolvers to get details of specific runs (#89)
On the instrumentSession object, run takes a scan number as these should be unique within a session. On the root, it takes a run id as these should be unique across tiled.
1 parent 6fb304d commit be5396d

File tree

3 files changed

+34
-3
lines changed

3 files changed

+34
-3
lines changed

src/clients.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,16 @@ impl TiledClient {
6969
self.request(&format!("api/v1/search/{}", path), headers, Some(query))
7070
.await
7171
}
72+
73+
pub async fn metadata(
74+
&self,
75+
id: String,
76+
headers: Option<HeaderMap>,
77+
) -> ClientResult<node::Metadata> {
78+
self.request(&format!("api/v1/metadata/{id}"), headers, None)
79+
.await
80+
}
81+
7282
pub async fn table_full(
7383
&self,
7484
path: &str,

src/model.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use serde_json::Value;
1313
use tracing::{info, instrument};
1414

1515
use crate::RootAddress;
16-
use crate::clients::TiledClient;
16+
use crate::clients::{ClientError, TiledClient};
1717
use crate::handlers::AuthHeader;
1818
use crate::model::node::NodeAttributes;
1919

@@ -29,6 +29,18 @@ impl TiledQuery {
2929
async fn instrument_session(&self, name: String) -> InstrumentSession {
3030
InstrumentSession { name }
3131
}
32+
33+
async fn run(&self, ctx: &Context<'_>, id: String) -> Result<Option<Run>> {
34+
let auth = ctx.data::<Option<AuthHeader>>()?;
35+
let headers = auth.as_ref().map(AuthHeader::as_header_map);
36+
match ctx.data::<TiledClient>()?.metadata(id, headers).await {
37+
Ok(run) => Ok(Some(Run {
38+
data: run.into_data(),
39+
})),
40+
Err(ClientError::TiledRequest(404, _)) => Ok(None),
41+
Err(other) => Err(other.into()),
42+
}
43+
}
3244
}
3345

3446
struct InstrumentSession {

src/model/node.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@ use serde_json::Value;
66

77
use crate::model::{array, container, table};
88

9+
pub type Root = Response<Vec<DataOption>>;
10+
pub type Metadata = Response<Data>;
11+
912
#[derive(Debug, PartialEq, Serialize, Deserialize)]
10-
pub struct Root {
11-
data: Vec<DataOption>,
13+
pub struct Response<D> {
14+
data: D,
1215
pub error: Value,
1316
pub links: Option<Links>,
1417
pub meta: Value,
@@ -23,6 +26,12 @@ impl Root {
2326
}
2427
}
2528

29+
impl Metadata {
30+
pub fn into_data(self) -> Data {
31+
self.data
32+
}
33+
}
34+
2635
#[derive(Debug, PartialEq, Serialize, Deserialize)]
2736
#[serde(untagged)]
2837
pub enum DataOption {

0 commit comments

Comments
 (0)