#![allow(clippy::too_many_arguments, unused_imports, non_camel_case_types)]
use serde::{Deserialize, Serialize};
use chrono::{DateTime, Utc};
use rust_decimal::Decimal;
use serde_json::Value as JsonValue;
use uuid::Uuid;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MarketPrice {
pub token_symbol: String,
pub price_usd: Decimal,
pub price_change_24h: Decimal,
pub source: String,
pub market_cap_usd: Decimal,
pub volume_24h_usd: Decimal,
pub id: Uuid,
pub created_at: DateTime<Utc>,
pub updated_at: DateTime<Utc>,
pub created_by: String,
pub updated_by: String,
}
impl MarketPrice {
pub fn new(
token_symbol: String,
price_usd: Decimal,
price_change_24h: Decimal,
source: String,
market_cap_usd: Decimal,
volume_24h_usd: Decimal,
id: Uuid,
created_at: DateTime<Utc>,
updated_at: DateTime<Utc>,
created_by: String,
updated_by: String,
) -> Self {
Self {
token_symbol,
price_usd,
price_change_24h,
source,
market_cap_usd,
volume_24h_usd,
id,
created_at,
updated_at,
created_by,
updated_by,
}
}
pub fn to_json(&self) -> Result<String, serde_json::Error> {
serde_json::to_string(self)
}
pub fn from_json(json: &str) -> Result<Self, serde_json::Error> {
serde_json::from_str(json)
}
pub fn to_dict(&self) -> serde_json::Map<String, serde_json::Value> {
let json = serde_json::to_value(self).unwrap_or(serde_json::Value::Null);
if let serde_json::Value::Object(map) = json {
map
} else {
serde_json::Map::new()
}
}
}