aboutsummaryrefslogtreecommitdiffstats
path: root/crates/configuration/src/server/http_svc/routes/typology/post_typology.rs
blob: 28643728f181d4a3af6cd7f32766a3d7e6f44f42 (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
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))
}