You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
1.2 KiB

use std::{fmt, str::FromStr};
use serde::{de, Deserialize, Deserializer};
pub mod company;
pub mod in_process_transaction;
pub mod transaction;
/// Struct to deserialize paginated routes query parameters
#[derive(Deserialize)]
pub struct Pagination {
#[serde(default, deserialize_with = "empty_string_as_none")]
pub page: Option<u64>,
#[serde(default, deserialize_with = "empty_string_as_none")]
pub size: Option<u64>,
}
/// Struct to deserialize a company slug as a query parameters
#[derive(Deserialize)]
pub struct CompanySlug {
#[serde(default, deserialize_with = "empty_string_as_none")]
pub company_slug: Option<String>,
}
/// Struct to deserialize a limit as a query parameters
#[derive(Deserialize)]
pub struct Limit {
#[serde(default, deserialize_with = "empty_string_as_none")]
pub limit: Option<u64>,
}
fn empty_string_as_none<'de, D, T>(de: D) -> Result<Option<T>, D::Error>
where
D: Deserializer<'de>,
T: FromStr,
T::Err: fmt::Display,
{
let opt = Option::<String>::deserialize(de)?;
match opt.as_deref() {
None | Some("") => Ok(None),
Some(s) => FromStr::from_str(s).map_err(de::Error::custom).map(Some),
}
}