use axum::{ Extension, Json, extract::{Path, State}, }; use serde::Deserialize; use serde_json::{Value, json}; use crate::{ auth::AuthenticatedSession, error::ApiError, request_context::RequestContext, service::{AdminAuditContext, AuthProfilePayload}, state::AppState, }; #[derive(Deserialize)] pub struct WorkspacePath { pub workspace_id: String, } #[derive(Deserialize)] pub struct WorkspaceAuthProfilePath { pub workspace_id: String, pub auth_profile_id: String, } pub async fn list_auth_profiles( Path(path): Path, State(state): State, ) -> Result, ApiError> { let items = state .service .list_auth_profiles(&path.workspace_id.as_str().into()) .await?; Ok(Json(json!({ "items": items }))) } pub async fn create_auth_profile( Path(path): Path, State(state): State, Extension(session): Extension, Extension(request_context): Extension, Json(payload): Json, ) -> Result, ApiError> { let audit_context = AdminAuditContext::from_session_and_correlation(&session, &request_context.correlation); let profile = state .service .create_auth_profile( &path.workspace_id.as_str().into(), payload, Some(&audit_context), ) .await?; Ok(Json(json!(profile))) } pub async fn get_auth_profile( Path(path): Path, State(state): State, ) -> Result, ApiError> { let profile = state .service .get_auth_profile( &path.workspace_id.as_str().into(), &path.auth_profile_id.as_str().into(), ) .await?; Ok(Json(json!(profile))) }