Skip to content

Commit

Permalink
test: more shenanigans with query string
Browse files Browse the repository at this point in the history
  • Loading branch information
rymnc committed Dec 17, 2024
1 parent d08f4d7 commit 1485452
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions committer/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,13 @@ async fn metrics(registry: web::Data<Arc<Registry>>) -> impl Responder {
#[serde(rename_all = "lowercase")]
enum HeightVariant {
Latest,
Height(u32),
Specific,
}

#[derive(Deserialize)]
struct CostQueryParams {
variant: HeightVariant,
value: Option<u32>,
limit: Option<usize>,
}

Expand All @@ -112,7 +113,12 @@ async fn costs(

let response = match query.variant {
HeightVariant::Latest => data.get_latest_costs(limit).await,
HeightVariant::Height(from_height) => data.get_costs(from_height, limit).await,
HeightVariant::Specific => {
let from_height = query
.value
.ok_or_else(|| services::Error::Other("height value is required".to_string()))?;
data.get_costs(from_height, limit).await
}
};

match response {
Expand Down

0 comments on commit 1485452

Please sign in to comment.