diff options
author | rtkay123 <dev@kanjala.com> | 2025-08-16 10:08:51 +0200 |
---|---|---|
committer | rtkay123 <dev@kanjala.com> | 2025-08-16 10:08:51 +0200 |
commit | eb59714648bbba66e77955c8bda1c99caf1cede6 (patch) | |
tree | 5c194cd5e132c172e4cb510cc35bb46594f86f02 /crates/configuration/src/server | |
parent | 698633baa2505ffb60cb5bba588f8b360c767edd (diff) | |
download | warden-eb59714648bbba66e77955c8bda1c99caf1cede6.tar.bz2 warden-eb59714648bbba66e77955c8bda1c99caf1cede6.zip |
feat(config): typologies
Diffstat (limited to 'crates/configuration/src/server')
7 files changed, 171 insertions, 0 deletions
diff --git a/crates/configuration/src/server/http_svc.rs b/crates/configuration/src/server/http_svc.rs index b07aece..423d67d 100644 --- a/crates/configuration/src/server/http_svc.rs +++ b/crates/configuration/src/server/http_svc.rs @@ -12,6 +12,7 @@ use crate::state::AppHandle; const TAG_ROUTING: &str = "Routing"; const TAG_RULES: &str = "Rules"; +const TAG_TYPOLOGIES: &str = "Typologies"; #[derive(OpenApi)] #[openapi( diff --git a/crates/configuration/src/server/http_svc/routes.rs b/crates/configuration/src/server/http_svc/routes.rs index 7663da2..92f3184 100644 --- a/crates/configuration/src/server/http_svc/routes.rs +++ b/crates/configuration/src/server/http_svc/routes.rs @@ -1,5 +1,6 @@ mod routing; mod rule; +mod typology; use utoipa_axum::{router::OpenApiRouter, routes}; @@ -21,5 +22,12 @@ pub fn router(store: AppHandle) -> OpenApiRouter { rule::delete::delete_rule_config, rule::get::get_rule, )) + .routes(routes!( + /* typology */ + typology::get_typology::get_typology, + typology::post_typology::update, + typology::delete_typology::delete_typology, + typology::create_typology::create_typology, + )) .with_state(store) } diff --git a/crates/configuration/src/server/http_svc/routes/typology.rs b/crates/configuration/src/server/http_svc/routes/typology.rs new file mode 100644 index 0000000..85a593b --- /dev/null +++ b/crates/configuration/src/server/http_svc/routes/typology.rs @@ -0,0 +1,4 @@ +pub mod create_typology; +pub mod delete_typology; +pub mod get_typology; +pub mod post_typology; diff --git a/crates/configuration/src/server/http_svc/routes/typology/create_typology.rs b/crates/configuration/src/server/http_svc/routes/typology/create_typology.rs new file mode 100644 index 0000000..9f4985a --- /dev/null +++ b/crates/configuration/src/server/http_svc/routes/typology/create_typology.rs @@ -0,0 +1,38 @@ +use axum::{extract::State, response::IntoResponse}; +use warden_core::configuration::typology::{ + TypologyConfiguration, mutate_typologies_server::MutateTypologies, +}; + +use crate::{ + server::{error::AppError, http_svc::TAG_TYPOLOGIES, version::Version}, + state::AppHandle, +}; + +/// Create rule configuration +#[utoipa::path( + post, + path = "/{version}/typology", + params( + ("version" = Version, Path, description = "API version, e.g., v1, v2, v3"), + ), + responses(( + status = CREATED, + body = TypologyConfiguration, + )), + operation_id = "create_typology_configuration", // https://github.com/juhaku/utoipa/issues/1170 + tag = TAG_TYPOLOGIES, + ) +] +#[axum::debug_handler] +#[tracing::instrument(skip(state))] +pub async fn create_typology( + version: Version, + State(state): State<AppHandle>, + axum::Json(body): axum::Json<TypologyConfiguration>, +) -> Result<impl IntoResponse, AppError> { + let response = state + .create_typology_configuration(tonic::Request::new(body)) + .await? + .into_inner(); + Ok((axum::http::StatusCode::CREATED, axum::Json(response))) +} diff --git a/crates/configuration/src/server/http_svc/routes/typology/delete_typology.rs b/crates/configuration/src/server/http_svc/routes/typology/delete_typology.rs new file mode 100644 index 0000000..0e85e29 --- /dev/null +++ b/crates/configuration/src/server/http_svc/routes/typology/delete_typology.rs @@ -0,0 +1,41 @@ +use axum::extract::{Query, State}; +use tonic::IntoRequest; +use warden_core::configuration::typology::{ + DeleteTypologyConfigurationRequest, TypologyConfiguration, + mutate_typologies_server::MutateTypologies, +}; + +use crate::{ + server::{error::AppError, http_svc::TAG_TYPOLOGIES, version::Version}, + state::AppHandle, +}; + +/// Get the typology configuration +#[utoipa::path( + delete, + path = "/{version}/typology", + responses(( + status = OK, + body = TypologyConfiguration + )), + params( + ("version" = Version, Path, description = "API version, e.g., v1, v2, v3"), + DeleteTypologyConfigurationRequest + ), + operation_id = "delete_typology_configuration", // https://github.com/juhaku/utoipa/issues/1170 + tag = TAG_TYPOLOGIES, + ) +] +#[axum::debug_handler] +#[tracing::instrument(skip(state))] +pub async fn delete_typology( + State(state): State<AppHandle>, + Query(params): Query<DeleteTypologyConfigurationRequest>, +) -> Result<axum::Json<TypologyConfiguration>, AppError> { + let config = state + .delete_typology_configuration(params.into_request()) + .await? + .into_inner(); + + Ok(axum::Json(config)) +} diff --git a/crates/configuration/src/server/http_svc/routes/typology/get_typology.rs b/crates/configuration/src/server/http_svc/routes/typology/get_typology.rs new file mode 100644 index 0000000..4962593 --- /dev/null +++ b/crates/configuration/src/server/http_svc/routes/typology/get_typology.rs @@ -0,0 +1,40 @@ +use axum::extract::{Query, State}; +use tonic::IntoRequest; +use warden_core::configuration::typology::{ + TypologyConfiguration, TypologyConfigurationRequest, query_typologies_server::QueryTypologies, +}; + +use crate::{ + server::{error::AppError, http_svc::TAG_TYPOLOGIES, version::Version}, + state::AppHandle, +}; + +/// Get the typology configuration +#[utoipa::path( + get, + path = "/{version}/typology", + responses(( + status = OK, + body = TypologyConfiguration + )), + params( + ("version" = Version, Path, description = "API version, e.g., v1, v2, v3"), + TypologyConfigurationRequest + ), + operation_id = "get_typology_configuration", // https://github.com/juhaku/utoipa/issues/1170 + tag = TAG_TYPOLOGIES, + ) +] +#[axum::debug_handler] +#[tracing::instrument(skip(state))] +pub async fn get_typology( + State(state): State<AppHandle>, + Query(params): Query<TypologyConfigurationRequest>, +) -> Result<axum::Json<Option<TypologyConfiguration>>, AppError> { + let config = state + .get_typology_configuration(params.into_request()) + .await? + .into_inner(); + + Ok(axum::Json(config.configuration)) +} diff --git a/crates/configuration/src/server/http_svc/routes/typology/post_typology.rs b/crates/configuration/src/server/http_svc/routes/typology/post_typology.rs new file mode 100644 index 0000000..2864372 --- /dev/null +++ b/crates/configuration/src/server/http_svc/routes/typology/post_typology.rs @@ -0,0 +1,39 @@ +use axum::extract::State; +use warden_core::configuration::typology::{ + TypologyConfiguration, UpdateTypologyConfigRequest, mutate_typologies_server::MutateTypologies, +}; + +use crate::{ + server::{error::AppError, http_svc::TAG_TYPOLOGIES, version::Version}, + state::AppHandle, +}; + +/// Update typology configuration +#[utoipa::path( + put, + path = "/{version}/typology", + params( + ("version" = Version, Path, description = "API version, e.g., v1, v2, v3"), + ), + responses(( + status = OK, + body = TypologyConfiguration + )), + operation_id = "update_typology_configuration", // https://github.com/juhaku/utoipa/issues/1170 + tag = TAG_TYPOLOGIES, + ) +] +#[axum::debug_handler] +#[tracing::instrument(skip(state))] +pub async fn update( + State(state): State<AppHandle>, + axum::Json(body): axum::Json<TypologyConfiguration>, +) -> Result<axum::Json<TypologyConfiguration>, AppError> { + let response = state + .update_typology_configuration(tonic::Request::new(UpdateTypologyConfigRequest { + configuration: Some(body), + })) + .await? + .into_inner(); + Ok(axum::Json(response)) +} |