pinakes/crates/pinakes-server/src/routes/audit.rs
NotAShelf 9d58927cb4
pinakes-server: add utoipa annotations to all routes; fix tests
Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: I28cf5b7b7cff8e90e123d624d97cf9656a6a6964
2026-03-22 22:04:51 +03:00

36 lines
1,012 B
Rust

use axum::{
Json,
extract::{Query, State},
};
use crate::{
dto::{AuditEntryResponse, PaginationParams},
error::ApiError,
state::AppState,
};
#[utoipa::path(
get,
path = "/api/v1/audit",
tag = "audit",
params(
("offset" = Option<u64>, Query, description = "Pagination offset"),
("limit" = Option<u64>, Query, description = "Page size"),
),
responses(
(status = 200, description = "Audit log entries", body = Vec<AuditEntryResponse>),
(status = 401, description = "Unauthorized"),
(status = 500, description = "Internal server error"),
),
security(("bearer_auth" = []))
)]
pub async fn list_audit(
State(state): State<AppState>,
Query(params): Query<PaginationParams>,
) -> Result<Json<Vec<AuditEntryResponse>>, ApiError> {
let pagination = params.to_pagination();
let entries = state.storage.list_audit_entries(None, &pagination).await?;
Ok(Json(
entries.into_iter().map(AuditEntryResponse::from).collect(),
))
}