Skip to content
Clone
971c37c
33 lines 867 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::BadRequest(export::rest::AppResponseData::err(
400,
"invalid request path",
))
})
}
}