use crate::Context; use axum::{ extract::{Path, State}, http::StatusCode, Json, }; use verax::{AnyId, Filter, Type}; /// TODO: Implement the http caching pub async fn handler( Path(id): Path, State(ctx): State, ) -> Result>, (StatusCode, String)> { let (_cache_for_ever, filter) = match id { AnyId::Account(account_id) => ( false, Filter { from: vec![account_id], typ: vec![Type::Deposit, Type::Withdrawal, Type::Transaction], ..Default::default() }, ), AnyId::Revision(rev_id) => ( true, Filter { revisions: vec![rev_id], limit: 1, ..Default::default() }, ), AnyId::Transaction(transaction_id) => ( false, Filter { ids: vec![transaction_id], limit: 1, ..Default::default() }, ), AnyId::Payment(payment_id) => { let _ = ctx.ledger.get_payment_info(&payment_id).await; todo!() } }; ctx.ledger .get_transactions(filter) .await .map(Json) /* .map(|results| { /// REVISIT LATER TO IMPLEMENT THE CACHE let json_response = if limit == 1 { serde_json::to_value(&results[0]) } else { serde_json::to_value(&results) } .unwrap(); if cache_for_ever { HttpResponse::Ok() .header( "Cache-Control", "public, max-age=31536000, s-maxage=31536000, immutable", ) .header("Vary", "Accept-Encoding") .json(json_response) } else { HttpResponse::Ok().json(json_response) } json_response }) */ .map_err(|err| { ( StatusCode::BAD_REQUEST, serde_json::to_string(&err).unwrap_or_default(), ) }) }