use std::str::FromStr; use bigdecimal::{BigDecimal, ParseBigDecimalError}; use serde::{Deserialize, Serialize}; use sqlx::{Database, Decode, Encode, FromRow, Type, error::BoxDynError}; use std::cmp::PartialOrd; use std::error::Error; use std::fmt::Display; // use validator::{Validate, ValidateRange}; // #[derive(Debug, Serialize, Deserialize, PartialEq, PartialOrd, Clone, Type)] // #[sqlx(transparent)] // pub struct Amount(BigDecimal); // impl Amount { // fn new(text: &str) -> Result { // Ok(Amount(BigDecimal::from_str(text)?)) // } // } // impl Display for Amount { // fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { // self.0.fmt(f) // } // } // impl ValidateRange for Amount { // fn greater_than(&self, max: Amount) -> Option { // Some(self > &max) // } // fn less_than(&self, min: Amount) -> Option { // Some(self < &min) // } // } // impl From for BigDecimal { // fn from(value: Amount) -> Self { // value.0 // } // } type Amount = BigDecimal; #[derive(Debug, Serialize, Deserialize, FromRow)] pub struct Account { pub account_id: i64, pub balance: Amount, } #[derive(Debug, Serialize, Deserialize)] pub struct CreateAccount { pub account_id: i64, pub initial_balance: Amount, } #[derive(Debug, Serialize, Deserialize)] pub struct TransactionRequest { pub source_account_id: i64, pub destination_account_id: i64, pub amount: Amount, }