shield-axum 0.2.5

Axum integration for Shield.
Documentation
use axum::{Json, extract::Path};
use shield::{ActionForms, ActionFormsPathParams, User};

#[cfg(feature = "utoipa")]
use crate::error::ErrorBody;
use crate::{ExtractSession, ExtractShield, RouteError};

#[cfg_attr(
    feature = "utoipa",
    utoipa::path(
        get,
        path = "/forms/{actionId}",
        operation_id = "getActionForms",
        summary = "Get action forms",
        description = "Get action forms.",
        tags = ["auth"],
        params(
            ActionFormsPathParams
        ),
        responses(
            (status = OK, description = "The action forms.", body = ActionForms),
            (status = INTERNAL_SERVER_ERROR, description = "Internal server error.", body = ErrorBody),
        )
    )
)]
pub async fn forms<U: User>(
    Path(ActionFormsPathParams { action_id, .. }): Path<ActionFormsPathParams>,
    ExtractShield(shield): ExtractShield<U>,
    ExtractSession(session): ExtractSession,
) -> Result<Json<ActionForms>, RouteError> {
    let forms = shield.action_forms(&action_id, session).await?;

    Ok(Json(forms))
}