Skip to content
Clone
a06673b
27 lines 894 B Rust
use axum::Json;
use axum::extract::{Path, State};
use jwt::extractor::AuthUser;
use uuid::Uuid;
use crate::error::RepoResult;
use crate::features::RepoService;
use crate::features::compare::CompareView;
#[utoipa::path(
get,
path = "/repo/{channel_id}/{repo_id}/compare/{base}...{head}",
tag = "repo",
responses((status = 200, description = "Compare two refs", body = CompareView)),
security(("bearer_auth" = []))
)]
pub(crate) async fn handler(
State(svc): State<RepoService>,
AuthUser { claims }: AuthUser,
Path((_, repo_id, base_dot_head)): Path<(Uuid, Uuid, String)>,
) -> RepoResult<Json<CompareView>> {
let (base, head) = base_dot_head
.split_once("...")
.ok_or_else(|| crate::error::RepoError::BadRequest("expected '<base>...<head>'".into()))?;
let view = svc.compare(claims.sub, repo_id, base, head).await?;
Ok(Json(view))
}