use crate::api::response::ApiResponse; use crate::error::AppError; use crate::service::AppService; use crate::session::Session; use actix_web::{HttpResponse, web}; use serde::Deserialize; use utoipa::IntoParams; #[derive(Debug, Deserialize, IntoParams)] pub struct PathParams { pub workspace_name: String, pub repo_name: String, } #[derive(Debug, Deserialize, IntoParams)] pub struct RevisionPathParams { pub workspace_name: String, pub repo_name: String, pub revision: String, } #[derive(Debug, Deserialize, IntoParams)] pub struct FindCommitQuery { pub revision: String, } #[utoipa::path(get, path = "/api/v1/workspaces/{workspace_name}/repos/{repo_name}/git/find-commit", tag = "Git", operation_id = "gitFindCommit", params(PathParams, FindCommitQuery), responses((status=200,body=ApiResponse)), security(("session_cookie"=[])))] pub async fn git_find_commit( service: web::Data, session: Session, path: web::Path, q: web::Query, ) -> Result { let r = service .repo .git_find_commit(&session, &path.workspace_name, &path.repo_name, &q.revision) .await?; Ok(HttpResponse::Ok().json(ApiResponse::new(r))) } #[derive(Debug, Deserialize, utoipa::ToSchema)] pub struct ListCommitsByOidBody { pub oids: Vec, } #[utoipa::path(post, path = "/api/v1/workspaces/{workspace_name}/repos/{repo_name}/git/commits/by-oid", tag = "Git", operation_id = "gitCommitsByOid", params(PathParams), request_body(content=ListCommitsByOidBody), responses((status=200,body=ApiResponse)), security(("session_cookie"=[])))] pub async fn git_commits_by_oid( service: web::Data, session: Session, path: web::Path, body: web::Json, ) -> Result { let oids: Vec> = body .oids .iter() .map(|s| hex::decode(s).unwrap_or_default()) .collect(); let r = service .repo .git_list_commits_by_oid(&session, &path.workspace_name, &path.repo_name, oids) .await?; Ok(HttpResponse::Ok().json(ApiResponse::new(r))) } #[derive(Debug, Deserialize, IntoParams)] pub struct AncestorQuery { pub ancestor: String, pub descendant: String, } #[utoipa::path(get, path = "/api/v1/workspaces/{workspace_name}/repos/{repo_name}/git/commit-is-ancestor", tag = "Git", operation_id = "gitCommitIsAncestor", params(PathParams, AncestorQuery), responses((status=200,body=ApiResponse)), security(("session_cookie"=[])))] pub async fn git_commit_is_ancestor( service: web::Data, session: Session, path: web::Path, q: web::Query, ) -> Result { let r = service .repo .git_commit_is_ancestor( &session, &path.workspace_name, &path.repo_name, &q.ancestor, &q.descendant, ) .await?; Ok(HttpResponse::Ok().json(ApiResponse::new(r))) } #[derive(Debug, Deserialize, IntoParams)] pub struct LastCommitQuery { pub path: String, pub revision: Option, } #[utoipa::path(get, path = "/api/v1/workspaces/{workspace_name}/repos/{repo_name}/git/last-commit", tag = "Git", operation_id = "gitLastCommitForPath", params(PathParams, LastCommitQuery), responses((status=200,body=ApiResponse)), security(("session_cookie"=[])))] pub async fn git_last_commit( service: web::Data, session: Session, path: web::Path, q: web::Query, ) -> Result { let r = service .repo .git_last_commit_for_path( &session, &path.workspace_name, &path.repo_name, &q.path, q.revision.as_deref(), ) .await?; Ok(HttpResponse::Ok().json(ApiResponse::new(r))) } #[derive(Debug, Deserialize, IntoParams)] pub struct CommitsByMsgQuery { pub q: String, pub revision: Option, pub limit: Option, } #[utoipa::path(get, path = "/api/v1/workspaces/{workspace_name}/repos/{repo_name}/git/commits/search", tag = "Git", operation_id = "gitCommitsByMessage", params(PathParams, CommitsByMsgQuery), responses((status=200,body=ApiResponse)), security(("session_cookie"=[])))] pub async fn git_commits_by_message( service: web::Data, session: Session, path: web::Path, q: web::Query, ) -> Result { let r = service .repo .git_commits_by_message( &session, &path.workspace_name, &path.repo_name, &q.q, q.revision.as_deref(), q.limit.unwrap_or(20), ) .await?; Ok(HttpResponse::Ok().json(ApiResponse::new(r))) }