mirror of
https://github.com/andwati/telecom-platform.git
synced 2026-11-02 01:42:19 +00:00
feat: Add data models for charging engine API endpoints
- Add AppState struct to hold shared ChargingEngine instance - Add CreditCheckRequest and CreditCheckResponse for credit validation - Add DeductRequest for byte usage deduction - Add AddCreditRequest for credit top-up operations - Add BalanceResponse for IP address balance queries - Add HealthResponse with default implementation for health check endpoint - Derive Serialize/Deserialize traits for API request/response types
This commit is contained in:
@@ -0,0 +1,48 @@
|
|||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub struct AppState {
|
||||||
|
pub charging_engine: std::sync::Arc<crate::charging::ChargingEngine>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
pub struct CreditCheckRequest {
|
||||||
|
pub bytes_requested: u64,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize)]
|
||||||
|
pub struct CreditCheckResponse {
|
||||||
|
pub allowed: bool,
|
||||||
|
pub remaining_bytes: i64,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
pub struct DeductRequest {
|
||||||
|
pub bytes_used: u64,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
pub struct AddCreditRequest {
|
||||||
|
pub bytes_to_add: u64,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize)]
|
||||||
|
pub struct BalanceResponse {
|
||||||
|
pub ip: String,
|
||||||
|
pub balance_bytes: i64,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize)]
|
||||||
|
pub struct HealthResponse {
|
||||||
|
pub status: String,
|
||||||
|
pub timestamp: chrono::DateTime<chrono::Utc>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for HealthResponse {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self {
|
||||||
|
status: "OK".to_string(),
|
||||||
|
timestamp: chrono::Utc::now(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user