feat(frontend): request logs; refactor frontend components
This commit is contained in:
@@ -7,7 +7,10 @@ use axum::{
|
||||
};
|
||||
use tracing::error;
|
||||
|
||||
use crate::{AppState, auth, crypto, db};
|
||||
use crate::{
|
||||
AppState, auth,
|
||||
db::{self, models::RequestLog},
|
||||
};
|
||||
|
||||
use super::models::*;
|
||||
|
||||
@@ -348,3 +351,19 @@ pub async fn update_config(
|
||||
|
||||
Ok(StatusCode::OK)
|
||||
}
|
||||
|
||||
// Log handlers
|
||||
pub async fn list_logs(
|
||||
State(state): State<Arc<AppState>>,
|
||||
) -> Result<Json<Vec<RequestLog>>, (StatusCode, Json<ApiError>)> {
|
||||
match db::repositories::logs::list_all(&state.db).await {
|
||||
Ok(logs) => Ok(Json(logs)),
|
||||
Err(e) => {
|
||||
error!("Failed to list logs: {}", e);
|
||||
Err((
|
||||
StatusCode::INTERNAL_SERVER_ERROR,
|
||||
Json(ApiError::new("Failed to fetch logs")),
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,3 +99,21 @@ impl ApiError {
|
||||
Self { error: msg.into() }
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
pub struct RequestDetails {
|
||||
pub headers: Vec<Header>,
|
||||
pub body: Body,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
pub struct Body {
|
||||
pub value: Value,
|
||||
pub modified: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct Header {
|
||||
pub value: String,
|
||||
pub modified: bool,
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ pub fn admin_routes(state: Arc<AppState>) -> Router<Arc<AppState>> {
|
||||
.route("/api/commands/{:id}", post(handlers::verify_command))
|
||||
.route("/api/config", get(handlers::get_config))
|
||||
.route("/api/config", put(handlers::update_config))
|
||||
.route("/api/logs", get(handlers::list_logs))
|
||||
.layer(axum::middleware::from_fn_with_state(
|
||||
state,
|
||||
auth_middleware::auth_middleware,
|
||||
|
||||
Reference in New Issue
Block a user