rust-api-template/src/api/routes/api_keys/handlers/apikeys_get.rs

30 lines
734 B
Rust
Raw Normal View History

2025-04-05 17:10:55 +00:00
use axum::{debug_handler, Extension, Json};
use crate::{
api::{
backend::ApiBackend,
description::API_KEY_TAG,
routes::api_keys::{models::ApiKey, sql},
},
errors::ApiError,
};
#[debug_handler]
#[utoipa::path(
get,
path = "/apikeys",
summary = "Get all API Keys",
description = "Get a list of all configured API Keys.",
responses(
(status = OK, body = Vec<ApiKey>, description = "List of API Keys"),
),
security(
("user_auth" = ["read:apikeys",]),
),
tag = API_KEY_TAG)]
pub async fn get_api_keys(
Extension(backend): Extension<ApiBackend>,
) -> Result<Json<Vec<ApiKey>>, ApiError> {
Ok(Json(sql::get_api_keys(backend.pool()).await?))
}