diff --git a/backend/crates/atlas-server/src/api/handlers/logs.rs b/backend/crates/atlas-server/src/api/handlers/logs.rs index 81a386c..0caed3b 100644 --- a/backend/crates/atlas-server/src/api/handlers/logs.rs +++ b/backend/crates/atlas-server/src/api/handlers/logs.rs @@ -7,7 +7,7 @@ use std::sync::Arc; use crate::api::error::ApiResult; use crate::api::AppState; -use atlas_common::{EventLog, PaginatedResponse, Pagination}; +use atlas_common::{EventLog, PaginatedResponse}; /// Pagination for transaction log endpoints. #[derive(Debug, Deserialize)] @@ -38,17 +38,19 @@ pub struct LogsQuery { /// Filter by event signature (topic0) pub topic0: Option, /// Optional pagination - #[serde(flatten)] - pub pagination: Pagination, + #[serde(default = "default_page")] + pub page: u32, + #[serde(default = "default_limit")] + pub limit: u32, } impl LogsQuery { fn clamped_limit(&self) -> u32 { - self.pagination.limit.min(100) + self.limit.min(100) } fn offset(&self) -> i64 { - (self.pagination.page.saturating_sub(1) as i64) * self.clamped_limit() as i64 + (self.page.saturating_sub(1) as i64) * self.clamped_limit() as i64 } fn limit(&self) -> i64 { @@ -147,7 +149,7 @@ pub async fn get_address_logs( Ok(Json(PaginatedResponse::new( logs, - query.pagination.page, + query.page, query.clamped_limit(), total, ))) @@ -253,6 +255,7 @@ fn normalize_address(address: &str) -> String { #[cfg(test)] mod tests { + use super::LogsQuery; use super::TransactionLogsQuery; use atlas_common::PaginatedResponse; @@ -272,4 +275,20 @@ mod tests { assert_eq!(response.limit, 100); assert_eq!(response.total_pages, 3); } + + #[test] + fn logs_query_parses_pagination_from_query_string() { + use axum::extract::Query; + use axum::http::Uri; + + let uri: Uri = "/?limit=20&page=2".parse().unwrap(); + let Query(q): Query = + Query::try_from_uri(&uri).expect("Should be able to parse the query string"); + + assert_eq!(q.page, 2); + assert_eq!(q.limit, 20); + + assert_eq!(q.limit(), 20); + assert_eq!(q.offset(), 20); + } }