aboutsummaryrefslogtreecommitdiffstats
path: root/crates/configuration/src/server/http_svc/routes/typology/create_typology.rs
blob: 9f4985a944c2fbd34bb6be8a5a2ef988b7f657ff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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)))
}