-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(atoma-daemon): endpoints (#282)
* chore: change endpoint names * wip * chore: fixed fmt * wip: refactor endpoints * refactor(atoma-daemon): endpoints * chore: update openapi.yml * chore: trim import path
- Loading branch information
1 parent
893a486
commit 88b06ec
Showing
10 changed files
with
230 additions
and
609 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
use atoma_state::types::StackSettlementTicket; | ||
use axum::{extract::Path, extract::State, http::StatusCode, routing::get, Json, Router}; | ||
use tracing::error; | ||
use utoipa::OpenApi; | ||
|
||
use crate::DaemonState; | ||
|
||
pub const CLAIMED_STACKS_PATH: &str = "/claimed-stacks"; | ||
|
||
#[derive(OpenApi)] | ||
#[openapi( | ||
paths(claimed_stacks_nodes_list), | ||
components(schemas(StackSettlementTicket)) | ||
)] | ||
pub(crate) struct ClaimedStacksOpenApi; | ||
|
||
pub fn claimed_stacks_router() -> Router<DaemonState> { | ||
Router::new().route( | ||
&format!("{CLAIMED_STACKS_PATH}/nodes/:node_id"), | ||
get(claimed_stacks_nodes_list), | ||
) | ||
} | ||
|
||
/// List claimed stacks | ||
/// | ||
/// Lists all claimed stacks for a specific node identified by its small ID. | ||
#[utoipa::path( | ||
get, | ||
path = "/claimed_stacks/nodes/{node_id}", | ||
params( | ||
("node_id" = i64, Path, description = "Node small ID") | ||
), | ||
responses( | ||
(status = OK, description = "List of claimed stacks matching the criteria", body = Vec<StackSettlementTicket>), | ||
(status = INTERNAL_SERVER_ERROR, description = "Internal server error") | ||
) | ||
)] | ||
pub async fn claimed_stacks_nodes_list( | ||
State(daemon_state): State<DaemonState>, | ||
Path(node_id): Path<i64>, | ||
) -> Result<Json<Vec<StackSettlementTicket>>, StatusCode> { | ||
let node_ids = vec![node_id]; | ||
|
||
daemon_state | ||
.atoma_state | ||
.get_claimed_stacks(&node_ids) | ||
.await | ||
.map(Json) | ||
.map_err(|_| { | ||
error!("Failed to get claimed stacks"); | ||
StatusCode::INTERNAL_SERVER_ERROR | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.