aboutsummaryrefslogtreecommitdiffstats
path: root/crates/configuration/src/server/http_svc/routes/routing/post_routing.rs
blob: 3578b657e83d32cfd9d7cfbda9da1b669f3f5691 (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, response::IntoResponse};
use warden_core::configuration::routing::{
    RoutingConfiguration, mutate_routing_server::MutateRouting,
};

use crate::{
    server::{error::AppError, http_svc::TAG_ROUTING, version::Version},
    state::AppHandle,
};

/// Create routing configuration
#[utoipa::path(
    post,
    responses((
        status = CREATED,
        body = RoutingConfiguration
    )),
    operation_id = "post_routing_configuration", // https://github.com/juhaku/utoipa/issues/1170
    path = "/{version}/routing",
    params(
        ("version" = Version, Path, description = "API version, e.g., v1, v2, v3")
    ),
    tag = TAG_ROUTING,
)
]
#[axum::debug_handler]
#[tracing::instrument(skip(state), err(Debug), fields(method = "POST"))]
pub async fn post_routing(
    version: Version,
    State(state): State<AppHandle>,
    axum::Json(body): axum::Json<RoutingConfiguration>,
) -> Result<impl IntoResponse, AppError> {
    let response = state
        .create_routing_configuration(tonic::Request::new(body))
        .await?
        .into_inner();

    Ok((axum::http::StatusCode::CREATED, axum::Json(response)))
}