use crate::{ApiResponse, error::ApiError}; use actix_web::{HttpResponse, Result, web}; use service::AppService; use service::git::init::GitInitRequest; use session::Session; #[utoipa::path( post, path = "/api/git/init", request_body = GitInitRequest, responses( (status = 200, description = "Bare repository initialized", body = ApiResponse), (status = 401, description = "Unauthorized", body = ApiResponse), (status = 404, description = "Not found", body = ApiResponse), ), tag = "Git" )] pub async fn git_init_bare( service: web::Data, body: web::Json, ) -> Result { let resp = service.git_init_bare(body.into_inner()).await?; Ok(ApiResponse::ok(resp).to_response()) } #[utoipa::path( get, path = "/api/git/open/{path}", params( ("path" = String, Path, description = "Repository path"), ), responses( (status = 200, description = "Open repository", body = ApiResponse), (status = 401, description = "Unauthorized", body = ApiResponse), (status = 404, description = "Not found", body = ApiResponse), ), tag = "Git" )] pub async fn git_open( service: web::Data, path: web::Path, ) -> Result { let resp = service.git_open(path.into_inner()).await?; Ok(ApiResponse::ok(resp).to_response()) } #[utoipa::path( get, path = "/api/git/open/{path}/workdir", params( ("path" = String, Path, description = "Repository path"), ), responses( (status = 200, description = "Open repository working directory", body = ApiResponse), (status = 401, description = "Unauthorized", body = ApiResponse), (status = 404, description = "Not found", body = ApiResponse), ), tag = "Git" )] pub async fn git_open_workdir( service: web::Data, path: web::Path, ) -> Result { let resp = service.git_open_workdir(path.into_inner()).await?; Ok(ApiResponse::ok(resp).to_response()) } #[utoipa::path( get, path = "/api/git/is-repo/{path}", params( ("path" = String, Path, description = "Repository path"), ), responses( (status = 200, description = "Check if path is a repository", body = ApiResponse), (status = 401, description = "Unauthorized", body = ApiResponse), (status = 404, description = "Not found", body = ApiResponse), ), tag = "Git" )] pub async fn git_is_repo( service: web::Data, path: web::Path, ) -> Result { let resp = service.git_is_repo(path.into_inner()).await?; Ok(ApiResponse::ok(resp).to_response()) } #[utoipa::path( get, path = "/api/repos/{namespace}/{repo}/git/path", params( ("namespace" = String, Path, description = "Repository namespace"), ("repo" = String, Path, description = "Repository name"), ), responses( (status = 200, description = "Repository path", body = ApiResponse), (status = 401, description = "Unauthorized", body = ApiResponse), (status = 404, description = "Not found", body = ApiResponse), ), tag = "Git" )] pub async fn git_repo_path( service: web::Data, session: Session, path: web::Path<(String, String)>, ) -> Result { let (namespace, repo_name) = path.into_inner(); let resp = service .git_repo_path(namespace, repo_name, &session) .await?; Ok(HttpResponse::Ok().json(serde_json::json!({ "path": resp }))) }