reafctor: all code without stream
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
use crate::api::errors::ApiError;
|
||||
use crate::api::state::SharedState;
|
||||
use crate::api::types::{CreateApiKeyRequest, CreateApiKeyResponse};
|
||||
use crate::core::auth::Auth;
|
||||
|
||||
use axum::{
|
||||
Json,
|
||||
extract::{Extension, State},
|
||||
};
|
||||
|
||||
pub async fn create_api_key(
|
||||
State(state): State<SharedState>,
|
||||
Extension(claims): Extension<Auth>,
|
||||
Json(body): Json<CreateApiKeyRequest>,
|
||||
) -> Result<Json<CreateApiKeyResponse>, ApiError> {
|
||||
let payload = crate::core::auth::api_key::CreateApiKeyRequest {
|
||||
user_id: claims.user_id(),
|
||||
name: body.name,
|
||||
roles: body.scopes.into_iter().map(Into::into).collect(),
|
||||
};
|
||||
|
||||
let key = state.auth_service.create_api_key(payload).await?;
|
||||
|
||||
Ok(Json(CreateApiKeyResponse { api_key: key }))
|
||||
}
|
||||
Reference in New Issue
Block a user