diff --git a/controller/src/api.rs b/controller/src/api.rs index 1906567..5c9b663 100644 --- a/controller/src/api.rs +++ b/controller/src/api.rs @@ -4,6 +4,7 @@ use dropshot::ApiDescription; use std::sync::Arc; use crate::context::ControllerContext; +use crate::updates; use crate::version; type ControllerApiDescription = ApiDescription>; @@ -11,5 +12,6 @@ type ControllerApiDescription = ApiDescription>; pub fn api() -> Result { let mut api = ControllerApiDescription::new(); api.register(version::version)?; + api.register(updates::get_latest)?; Ok(api) } diff --git a/controller/src/lib.rs b/controller/src/lib.rs index 0caaf72..eaf3ce7 100644 --- a/controller/src/lib.rs +++ b/controller/src/lib.rs @@ -1,4 +1,5 @@ pub mod api; pub mod context; +mod updates; mod version; diff --git a/controller/src/updates.rs b/controller/src/updates.rs new file mode 100644 index 0000000..cc53f90 --- /dev/null +++ b/controller/src/updates.rs @@ -0,0 +1,38 @@ +use dropshot::{endpoint, HttpError, HttpResponseOk, RequestContext}; +use schemars::JsonSchema; +use serde::Serialize; + +use std::sync::Arc; + +use crate::context::ControllerContext; +use trace_request::trace_request; + +/// Update information +#[derive(Serialize, JsonSchema)] +struct UpdateInfo { + name: String, +} + +/// Fetch update info +#[endpoint { + method = GET, + path = "/updates/latest", +}] +#[trace_request] +pub(crate) async fn get_latest( + rqctx: RequestContext>, +) -> Result, HttpError> { + let upd = UpdateInfo { + name: "Hello".to_string(), + }; + + tracing::info_span!("Hello, span!"); + + async move { + tracing::info!("Someone made a request to /updates/latest"); + tokio::time::sleep(std::time::Duration::from_millis(200)).await; + } + .instrument(tracing::info_span!("Let's do the thing....")) + .await; + Ok(HttpResponseOk(upd)) +}