aee0f09db8
- Datafabrik: Dockerfile fix, agentorkestrering fungerar - Vision: Identify-modell, FAISS, OCR alla testade - API: Alla 7 integrationstester passerade - Upplösare: Entitetsupplösning verifierad
57 lines
1.4 KiB
Rust
57 lines
1.4 KiB
Rust
use axum::{
|
|
extract::State,
|
|
response::Json,
|
|
};
|
|
use std::sync::Arc;
|
|
use crate::{AppState, models::*};
|
|
use serde_json::json;
|
|
|
|
pub async fn list_activity(State(state): State<Arc<AppState>>) -> Json<serde_json::Value> {
|
|
let activities = sqlx::query_as::<_, ActivityLog>(r#"
|
|
SELECT * FROM cc_activity_log
|
|
WHERE tenant_id = 'landvex'
|
|
ORDER BY created_at DESC
|
|
LIMIT 100
|
|
"#)
|
|
.fetch_all(&state.db)
|
|
.await
|
|
.unwrap_or_default();
|
|
|
|
Json(json!({
|
|
"ok": true,
|
|
"activities": activities,
|
|
"count": activities.len()
|
|
}))
|
|
}
|
|
|
|
pub async fn log_activity(
|
|
State(state): State<Arc<AppState>>,
|
|
Json(req): Json<CreateActivityRequest>,
|
|
) -> Json<serde_json::Value> {
|
|
let result = sqlx::query_as::<_, ActivityLog>(r#"
|
|
INSERT INTO cc_activity_log (action, entity_type, entity_id, user_id, details)
|
|
VALUES ($1, $2, $3, $4, $5)
|
|
RETURNING *
|
|
"#)
|
|
.bind(&req.action)
|
|
.bind(&req.entity_type)
|
|
.bind(&req.entity_id)
|
|
.bind(&req.user_id)
|
|
.bind(req.details.unwrap_or(json!({})))
|
|
.fetch_one(&state.db)
|
|
.await;
|
|
|
|
match result {
|
|
Ok(activity) => {
|
|
Json(json!({
|
|
"ok": true,
|
|
"id": activity.id
|
|
}))
|
|
}
|
|
Err(e) => Json(json!({
|
|
"ok": false,
|
|
"error": e.to_string()
|
|
}))
|
|
}
|
|
}
|