Skip to content
Clone
951a522
28 lines 736 B Rust
use axum::extract::{FromRequestParts, Path};
use axum::http::request::Parts;
use serde::Deserialize;
use utoipa::IntoParams;
use crate::errors::ApiError;
#[derive(Debug, Clone, Deserialize, IntoParams)]
pub struct PullPath {
pub space_name: String,
pub repo_name: String,
/// PR 编号(`12`)或 UUID。
pub pull_ref: String,
}
impl<S> FromRequestParts<S> for PullPath
where
S: Send + Sync,
{
type Rejection = ApiError;
async fn from_request_parts(parts: &mut Parts, state: &S) -> Result<Self, Self::Rejection> {
Path::<PullPath>::from_request_parts(parts, state)
.await
.map(|Path(p)| p)
.map_err(|_| ApiError::bad_request("invalid request path"))
}
}