aboutsummaryrefslogtreecommitdiffstats
path: root/crates/configuration/src/server/http_svc/routes
diff options
context:
space:
mode:
Diffstat (limited to 'crates/configuration/src/server/http_svc/routes')
-rw-r--r--crates/configuration/src/server/http_svc/routes/typology.rs4
-rw-r--r--crates/configuration/src/server/http_svc/routes/typology/create_typology.rs38
-rw-r--r--crates/configuration/src/server/http_svc/routes/typology/delete_typology.rs41
-rw-r--r--crates/configuration/src/server/http_svc/routes/typology/get_typology.rs40
-rw-r--r--crates/configuration/src/server/http_svc/routes/typology/post_typology.rs39
5 files changed, 162 insertions, 0 deletions
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))
+}