initial commit
This commit is contained in:
62
src/models.rs
Normal file
62
src/models.rs
Normal file
@@ -0,0 +1,62 @@
|
||||
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<Amount, ParseBigDecimalError> {
|
||||
// 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<Amount> for Amount {
|
||||
// fn greater_than(&self, max: Amount) -> Option<bool> {
|
||||
// Some(self > &max)
|
||||
// }
|
||||
|
||||
// fn less_than(&self, min: Amount) -> Option<bool> {
|
||||
// Some(self < &min)
|
||||
// }
|
||||
// }
|
||||
|
||||
// impl From<Amount> 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,
|
||||
}
|
Reference in New Issue
Block a user