revenue.rs (2411B)
1 /* 2 This file is part of TALER 3 Copyright (C) 2025, 2026 Taler Systems SA 4 5 TALER is free software; you can redistribute it and/or modify it under the 6 terms of the GNU Affero General Public License as published by the Free Software 7 Foundation; either version 3, or (at your option) any later version. 8 9 TALER is distributed in the hope that it will be useful, but WITHOUT ANY 10 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 11 A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. 12 13 You should have received a copy of the GNU Affero General Public License along with 14 TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> 15 */ 16 17 use std::sync::Arc; 18 19 use axum::{Json, Router, extract::State, http::StatusCode, response::IntoResponse, routing::get}; 20 use taler_common::{ 21 api_params::{History, HistoryParams}, 22 api_revenue::{RevenueConfig, RevenueIncomingHistory}, 23 }; 24 25 use super::TalerApi; 26 use crate::{ 27 api::RouterUtils as _, auth::AuthMethod, constants::REVENUE_API_VERSION, error::ApiResult, 28 extract::Query, 29 }; 30 31 pub trait Revenue: TalerApi { 32 fn history( 33 &self, 34 params: History, 35 ) -> impl std::future::Future<Output = ApiResult<RevenueIncomingHistory>> + Send; 36 } 37 38 pub fn router<I: Revenue>(state: Arc<I>, auth: AuthMethod) -> Router { 39 Router::new() 40 .route( 41 "/history", 42 get( 43 async |State(state): State<Arc<I>>, Query(params): Query<HistoryParams>| { 44 let params = params.check()?; 45 let history = state.history(params).await?; 46 ApiResult::Ok(if history.incoming_transactions.is_empty() { 47 StatusCode::NO_CONTENT.into_response() 48 } else { 49 Json(history).into_response() 50 }) 51 }, 52 ), 53 ) 54 .auth(auth, "taler-revenue") 55 .route( 56 "/config", 57 get(async |State(state): State<Arc<I>>| { 58 Json(RevenueConfig { 59 name: "taler-revenue", 60 version: REVENUE_API_VERSION, 61 currency: state.currency(), 62 implementation: Some(state.implementation()), 63 }) 64 .into_response() 65 }), 66 ) 67 .with_state(state) 68 }