use crate::{ApiResponse, error::ApiError}; use actix_web::{HttpResponse, Result, web}; use service::AppService; use service::git::blob::{ BlobContentResponse, BlobCreateRequest, BlobCreateResponse, BlobExistsResponse, BlobGetQuery, BlobInfoResponse, BlobIsBinaryResponse, BlobSizeResponse, GitReadmeQuery, GitReadmeResponse, }; use session::Session; #[utoipa::path( get, path = "/api/repos/{namespace}/{repo}/git/readme", params( ("namespace" = String, Path, description = "Project namespace"), ("repo" = String, Path, description = "Repository name"), ("ref" = Option, Query, description = "Git reference (branch, tag, commit). Defaults to HEAD."), ), responses( (status = 401, description = "Unauthorized", body = ApiResponse), (status = 200, description = "Get README content", body = ApiResponse), ), tag = "Git" )] pub async fn git_readme( service: web::Data, session: Session, path: web::Path<(String, String)>, query: web::Query, ) -> Result { let (namespace, repo_name) = path.into_inner(); let resp = service .git_readme(namespace, repo_name, query.into_inner(), &session) .await?; Ok(ApiResponse::ok(resp).to_response()) } #[utoipa::path( get, path = "/api/repos/{namespace}/{repo}/git/blob/{oid}", params( ("namespace" = String, Path, description = "Project namespace"), ("repo" = String, Path, description = "Repository name"), ("oid" = String, Path, description = "Blob object ID"), ), responses( (status = 401, description = "Unauthorized", body = ApiResponse), (status = 200, description = "Get blob info", body = ApiResponse), (status = 404, description = "Not found", body = ApiResponse), ), tag = "Git" )] pub async fn git_blob_get( service: web::Data, session: Session, path: web::Path<(String, String, String)>, query: web::Query, ) -> Result { let (namespace, repo_name, oid) = path.into_inner(); let mut req = query.into_inner(); req.oid = oid; let resp = service .git_blob_get(namespace, repo_name, req, &session) .await?; Ok(ApiResponse::ok(resp).to_response()) } #[utoipa::path( get, path = "/api/repos/{namespace}/{repo}/git/blob/{oid}/exists", params( ("namespace" = String, Path, description = "Project namespace"), ("repo" = String, Path, description = "Repository name"), ("oid" = String, Path, description = "Blob object ID"), ), responses( (status = 401, description = "Unauthorized", body = ApiResponse), (status = 200, description = "Check blob exists", body = ApiResponse), (status = 404, description = "Not found", body = ApiResponse), ), tag = "Git" )] pub async fn git_blob_exists( service: web::Data, session: Session, path: web::Path<(String, String, String)>, query: web::Query, ) -> Result { let (namespace, repo_name, oid) = path.into_inner(); let mut req = query.into_inner(); req.oid = oid; let resp = service .git_blob_exists(namespace, repo_name, req, &session) .await?; Ok(ApiResponse::ok(resp).to_response()) } #[utoipa::path( get, path = "/api/repos/{namespace}/{repo}/git/blob/{oid}/is-binary", params( ("namespace" = String, Path, description = "Project namespace"), ("repo" = String, Path, description = "Repository name"), ("oid" = String, Path, description = "Blob object ID"), ), responses( (status = 401, description = "Unauthorized", body = ApiResponse), (status = 200, description = "Check if blob is binary", body = ApiResponse), (status = 404, description = "Not found", body = ApiResponse), ), tag = "Git" )] pub async fn git_blob_is_binary( service: web::Data, session: Session, path: web::Path<(String, String, String)>, query: web::Query, ) -> Result { let (namespace, repo_name, oid) = path.into_inner(); let mut req = query.into_inner(); req.oid = oid; let resp = service .git_blob_is_binary(namespace, repo_name, req, &session) .await?; Ok(ApiResponse::ok(resp).to_response()) } #[utoipa::path( get, path = "/api/repos/{namespace}/{repo}/git/blob/{oid}/content", params( ("namespace" = String, Path, description = "Project namespace"), ("repo" = String, Path, description = "Repository name"), ("oid" = String, Path, description = "Blob object ID"), ), responses( (status = 401, description = "Unauthorized", body = ApiResponse), (status = 200, description = "Get blob content", body = ApiResponse), (status = 404, description = "Not found", body = ApiResponse), ), tag = "Git" )] pub async fn git_blob_content( service: web::Data, session: Session, path: web::Path<(String, String, String)>, query: web::Query, ) -> Result { let (namespace, repo_name, oid) = path.into_inner(); let mut req = query.into_inner(); req.oid = oid; let resp = service .git_blob_content(namespace, repo_name, req, &session) .await?; Ok(ApiResponse::ok(resp).to_response()) } #[utoipa::path( get, path = "/api/repos/{namespace}/{repo}/git/blob/{oid}/size", params( ("namespace" = String, Path, description = "Project namespace"), ("repo" = String, Path, description = "Repository name"), ("oid" = String, Path, description = "Blob object ID"), ), responses( (status = 401, description = "Unauthorized", body = ApiResponse), (status = 200, description = "Get blob size", body = ApiResponse), (status = 404, description = "Not found", body = ApiResponse), ), tag = "Git" )] pub async fn git_blob_size( service: web::Data, session: Session, path: web::Path<(String, String, String)>, query: web::Query, ) -> Result { let (namespace, repo_name, oid) = path.into_inner(); let mut req = query.into_inner(); req.oid = oid; let resp = service .git_blob_size(namespace, repo_name, req, &session) .await?; Ok(ApiResponse::ok(resp).to_response()) } #[utoipa::path( post, path = "/api/repos/{namespace}/{repo}/git/blob", request_body = BlobCreateRequest, params( ("namespace" = String, Path, description = "Project namespace"), ("repo" = String, Path, description = "Repository name"), ), responses( (status = 401, description = "Unauthorized", body = ApiResponse), (status = 200, description = "Create blob", body = ApiResponse), (status = 404, description = "Not found", body = ApiResponse), ), tag = "Git" )] pub async fn git_blob_create( service: web::Data, session: Session, path: web::Path<(String, String)>, body: web::Json, ) -> Result { let (namespace, repo_name) = path.into_inner(); let resp = service .git_blob_create(namespace, repo_name, body.into_inner(), &session) .await?; Ok(ApiResponse::ok(resp).to_response()) }