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:
nutcas3
2026-04-14 15:49:58 +03:00
parent f6effbf6d1
commit b84971c004
+48
View File
@@ -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(),
}
}
}