fix(payments): add time range in list payment attempts query (#5959)

Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
This commit is contained in:
Apoorv Dixit
2024-09-19 23:19:47 +05:30
committed by GitHub
parent 5942e059e9
commit 156a161f3e
40 changed files with 111 additions and 96 deletions

View File

@ -1,7 +1,7 @@
use common_enums::{PaymentMethod, PaymentMethodType};
use serde::Serialize;
use crate::id_type;
use crate::{id_type, types::TimeRange};
pub trait ApiEventMetric {
fn get_api_event_type(&self) -> Option<ApiEventsType> {
@ -139,3 +139,5 @@ impl<T: ApiEventMetric> ApiEventMetric for &T {
T::get_api_event_type(self)
}
}
impl ApiEventMetric for TimeRange {}

View File

@ -28,6 +28,7 @@ use rust_decimal::{
};
use semver::Version;
use serde::{de::Visitor, Deserialize, Deserializer, Serialize};
use time::PrimitiveDateTime;
use utoipa::ToSchema;
use crate::{
@ -582,6 +583,21 @@ impl StringMajorUnit {
}
}
/// A type representing a range of time for filtering, including a mandatory start time and an optional end time.
#[derive(
Debug, Clone, Copy, serde::Serialize, serde::Deserialize, PartialEq, Eq, Hash, ToSchema,
)]
pub struct TimeRange {
/// The start time to filter payments list or to get list of filters. To get list of filters start time is needed to be passed
#[serde(with = "crate::custom_serde::iso8601")]
#[serde(alias = "startTime")]
pub start_time: PrimitiveDateTime,
/// The end time to filter payments list or to get list of filters. If not passed the default time is now
#[serde(default, with = "crate::custom_serde::iso8601::option")]
#[serde(alias = "endTime")]
pub end_time: Option<PrimitiveDateTime>,
}
#[cfg(test)]
mod amount_conversion_tests {
#![allow(clippy::unwrap_used)]