Skip to content

Commit

Permalink
editoast: implement FromRef for CoreClient for easy access using State
Browse files Browse the repository at this point in the history
Signed-off-by: Leo Valais <[email protected]>
  • Loading branch information
leovalais committed Dec 4, 2024
1 parent 14c0c35 commit bbc9728
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions editoast/src/views/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,11 +334,7 @@ async fn version() -> Json<Version> {
(status = 200, description = "Return the core service version", body = Version),
),
)]
async fn core_version(
State(AppState {
core_client: core, ..
}): State<AppState>,
) -> Json<Version> {
async fn core_version(State(core): State<Arc<CoreClient>>) -> Json<Version> {
let response = CoreVersionRequest {}.fetch(&core).await;
let response = response.unwrap_or(Version { git_describe: None });
Json(response)
Expand Down Expand Up @@ -404,6 +400,12 @@ impl FromRef<AppState> for DbConnectionPoolV2 {
}
}

impl FromRef<AppState> for Arc<CoreClient> {
fn from_ref(input: &AppState) -> Self {
input.core_client.clone()
}
}

impl AppState {
async fn init(config: ServerConfig) -> Result<Self> {
info!("Building application state...");
Expand Down

0 comments on commit bbc9728

Please sign in to comment.