From 2e293bdd570a869103eba778a2b7d8ad08926763 Mon Sep 17 00:00:00 2001 From: Iris Date: Thu, 19 Oct 2023 12:46:17 +0200 Subject: [PATCH] fix: replace next_url by cursor in fetch_nfts endpoint --- src/endpoints/starkscan/fetch_nfts.rs | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/endpoints/starkscan/fetch_nfts.rs b/src/endpoints/starkscan/fetch_nfts.rs index 331ad2b..17855ba 100644 --- a/src/endpoints/starkscan/fetch_nfts.rs +++ b/src/endpoints/starkscan/fetch_nfts.rs @@ -16,7 +16,7 @@ use std::sync::Arc; #[derive(Deserialize)] pub struct FetchNftsQuery { addr: FieldElement, - next_url: Option, + cursor: Option, } #[derive(Serialize, Deserialize, Debug)] @@ -48,15 +48,14 @@ pub async fn handler( State(state): State>, Query(query): Query, ) -> impl IntoResponse { - let url = if let Some(next_url) = &query.next_url { - next_url.clone() - } else { - format!( - "{}nfts?owner_address={}", - state.conf.starkscan.api_url, - to_hex(&query.addr) - ) - }; + let base_url = format!( + "{}nfts?owner_address={}", + state.conf.starkscan.api_url, + to_hex(&query.addr) + ); + let url = query.cursor.as_ref().map_or(base_url.clone(), |cursor| { + format!("{}&cursor={}", base_url, cursor) + }); let client = reqwest::Client::new(); match client @@ -68,7 +67,10 @@ pub async fn handler( { Ok(response) => match response.text().await { Ok(text) => match serde_json::from_str::(&text) { - Ok(res) => (StatusCode::OK, Json(res)).into_response(), + Ok(res) => { + println!("Got response: {:?}", res); + (StatusCode::OK, Json(res)).into_response() + } Err(e) => get_error(format!( "Failed to deserialize result from Starkscan API: {} for response: {}", e, text