From eb59714648bbba66e77955c8bda1c99caf1cede6 Mon Sep 17 00:00:00 2001 From: rtkay123 Date: Sat, 16 Aug 2025 10:08:51 +0200 Subject: feat(config): typologies --- .../http_svc/routes/typology/create_typology.rs | 38 ++++++++++++++++++++ .../http_svc/routes/typology/delete_typology.rs | 41 ++++++++++++++++++++++ .../http_svc/routes/typology/get_typology.rs | 40 +++++++++++++++++++++ .../http_svc/routes/typology/post_typology.rs | 39 ++++++++++++++++++++ 4 files changed, 158 insertions(+) create mode 100644 crates/configuration/src/server/http_svc/routes/typology/create_typology.rs create mode 100644 crates/configuration/src/server/http_svc/routes/typology/delete_typology.rs create mode 100644 crates/configuration/src/server/http_svc/routes/typology/get_typology.rs create mode 100644 crates/configuration/src/server/http_svc/routes/typology/post_typology.rs (limited to 'crates/configuration/src/server/http_svc/routes/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, + axum::Json(body): axum::Json, +) -> Result { + 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, + Query(params): Query, +) -> Result, 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, + Query(params): Query, +) -> Result>, 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, + axum::Json(body): axum::Json, +) -> Result, AppError> { + let response = state + .update_typology_configuration(tonic::Request::new(UpdateTypologyConfigRequest { + configuration: Some(body), + })) + .await? + .into_inner(); + Ok(axum::Json(response)) +} -- cgit v1.2.3