feat: Add session counting methods for mentors and users; enhance registration queries with related data

This commit is contained in:
MythEclipse
2025-10-28 14:57:20 +07:00
parent b9a51ce6cc
commit 5e2b0d3caf
5 changed files with 221 additions and 25 deletions
@@ -1,6 +1,6 @@
use axum::{
body::Body,
http::{Request, Response},
http::{Request, Response, StatusCode, header::HeaderMap},
};
use futures::future::BoxFuture;
use imphnen_libs::AppState;
@@ -52,8 +52,52 @@ where
let mut inner = self.inner.clone();
let _app_state = self.app_state.clone();
Box::pin(async move {
// TODO: Implement payment validation logic here
// Payment validation logic
// Check for payment-related headers or query parameters
let headers = req.headers();
// Validate payment token if present
if let Some(payment_token) = headers.get("X-Payment-Token") {
if let Ok(token_str) = payment_token.to_str() {
// Basic validation: check token format
if !is_valid_payment_token(token_str) {
let error_response = Response::builder()
.status(StatusCode::PAYMENT_REQUIRED)
.body(Body::from("Invalid payment token"))
.unwrap();
return Err(error_response);
}
}
}
// Check if endpoint requires payment verification
let uri_path = req.uri().path();
if requires_payment_verification(uri_path) {
if !headers.contains_key("X-Payment-Token") {
let error_response = Response::builder()
.status(StatusCode::PAYMENT_REQUIRED)
.body(Body::from("Payment required for this endpoint"))
.unwrap();
return Err(error_response);
}
}
// Pass through if payment validation succeeds or not required
inner.call(req).await
})
}
}
/// Validate payment token format
fn is_valid_payment_token(token: &str) -> bool {
// Basic validation: token should be alphanumeric and at least 16 chars
token.len() >= 16 && token.chars().all(|c| c.is_alphanumeric() || c == '-' || c == '_')
}
/// Check if URI path requires payment verification
fn requires_payment_verification(path: &str) -> bool {
// Premium endpoints that require payment
path.contains("/premium/") ||
path.contains("/paid/") ||
path.contains("/subscription/")
}