use rocket::serde::json::Json; use rocket::Route; use rocket::State; use tracing::error; use crate::transactions::*; use crate::{Context, ErrorResponse}; #[rocket::get("/", format = "json")] async fn transaction_list( ctx: &State, ) -> Result>, ErrorResponse> { let result = ctx .firefly .search_transactions(&ctx.config.firefly.search_query) .await .map_err(|e| { error!("Error fetching transaction list: {}", e); ErrorResponse::new( "Failed to fetch transaction list from Firefly III", ) })?; Ok(Json( result .data .into_iter() .filter_map(|t| match Transaction::try_from(t) { Ok(t) => Some(t), Err(e) => { error!("Error parsing transaction details: {}", e); None }, }) .collect(), )) } pub fn routes() -> Vec { rocket::routes![transaction_list] }