Files
helios-server-rs/src/model/req.rs

36 lines
898 B
Rust
Raw Normal View History

2024-08-12 22:41:06 +08:00
use std::fmt;
use std::str::FromStr;
2024-08-11 09:25:09 +00:00
use serde::{de, Deserialize, Deserializer};
2024-08-12 23:37:07 +08:00
pub const QUERY_ORDER_INCREASE:i32 = 0;
pub const QUERY_ORDER_INVERT:i32 = 1;
pub const MAX_QUERY_LIMIT:i32 =1000;
2024-08-11 09:25:09 +00:00
#[derive(Debug, Deserialize)]
2024-08-12 23:37:07 +08:00
pub struct GetAmountParams {
2024-08-11 09:25:09 +00:00
#[serde(default, deserialize_with="empty_string_as_none")]
2024-08-12 22:41:06 +08:00
pub transaction_id: Option<i64>,
}
// Serde deserialization decorator to map empty Strings to None,
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),
}
}
2024-08-12 23:37:07 +08:00
#[derive(Deserialize)]
pub struct GetTransactionsQueryParams {
pub start: Option<i64>,
pub limit: Option<i32>,
}