generated from Patagia/template-nix
WIP: Add updates controller #5
3 changed files with 41 additions and 0 deletions
|
@ -4,6 +4,7 @@ use dropshot::ApiDescription;
|
|||
use std::sync::Arc;
|
||||
|
||||
use crate::context::ControllerContext;
|
||||
use crate::updates;
|
||||
use crate::version;
|
||||
|
||||
type ControllerApiDescription = ApiDescription<Arc<ControllerContext>>;
|
||||
|
@ -11,5 +12,6 @@ type ControllerApiDescription = ApiDescription<Arc<ControllerContext>>;
|
|||
pub fn api() -> Result<ControllerApiDescription> {
|
||||
let mut api = ControllerApiDescription::new();
|
||||
api.register(version::version)?;
|
||||
api.register(updates::get_latest)?;
|
||||
Ok(api)
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
pub mod api;
|
||||
pub mod context;
|
||||
|
||||
mod updates;
|
||||
mod version;
|
||||
|
|
38
controller/src/updates.rs
Normal file
38
controller/src/updates.rs
Normal file
|
@ -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<Arc<ControllerContext>>,
|
||||
) -> Result<HttpResponseOk<UpdateInfo>, 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))
|
||||
}
|
Loading…
Reference in a new issue