refactor: create separate struct for surcharge details response (#3027)

This commit is contained in:
Hrithikesh
2023-12-04 17:11:30 +05:30
committed by GitHub
parent 80efeb76b1
commit 57591f819c
14 changed files with 325 additions and 217 deletions

View File

@ -2,7 +2,10 @@
use error_stack::{IntoReport, ResultExt};
use serde::{de::Visitor, Deserialize, Deserializer};
use crate::errors::{CustomResult, PercentageError};
use crate::{
consts,
errors::{CustomResult, PercentageError},
};
/// Represents Percentage Value between 0 and 100 both inclusive
#[derive(Clone, Default, Debug, PartialEq, serde::Serialize)]
@ -136,3 +139,13 @@ impl<'de, const PRECISION: u8> Deserialize<'de> for Percentage<PRECISION> {
data.deserialize_map(PercentageVisitor::<PRECISION> {})
}
}
/// represents surcharge type and value
#[derive(Clone, Debug, PartialEq, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "snake_case", tag = "type", content = "value")]
pub enum Surcharge {
/// Fixed Surcharge value
Fixed(i64),
/// Surcharge percentage
Rate(Percentage<{ consts::SURCHARGE_PERCENTAGE_PRECISION_LENGTH }>),
}