use crate::api::BearerToken;
use crate::core::behavior_bio::BehaviorInput;
use crate::security::jwt::JwtManager;
use crate::AppState;
use actix_web::{post, web, HttpResponse, Responder};
use serde::Deserialize;
#[derive(Deserialize)]
pub struct BehaviorAnalyzeRequest {
pub input: BehaviorInput, }
#[post("/behavior/analyze")]
pub async fn analyze_behavior(
app_data: web::Data<AppState>,
payload: web::Json<BehaviorAnalyzeRequest>, bearer: BearerToken,
) -> impl Responder {
let token = bearer.0;
if token.is_empty() {
return HttpResponse::Unauthorized().body("Missing Authorization token");
}
let jwt_manager = JwtManager::new(
&crate::security::secret::SecureString::new(
"a_very_secure_and_long_secret_key_that_is_at_least_32_bytes_long".to_string(),
),
60,
"my_app".to_string(),
"user_service".to_string(),
);
if jwt_manager.decode_token(&token).is_err() {
return HttpResponse::Unauthorized().body("Invalid or expired token");
}
let engine = &app_data.x_engine.behavior_engine;
match engine.process(payload.input.clone()).await {
Ok(result) => HttpResponse::Ok().json(result), Err(e) => HttpResponse::InternalServerError().json(e.to_string()), }
}