use crate::{ApiResponse, error::ApiError}; use actix_web::{HttpResponse, Result, web}; use service::AppService; use service::git::refs::{ RefCreateRequest, RefDeleteResponse, RefExistsResponse, RefInfoResponse, RefListQuery, RefRenameQuery, RefTargetResponse, RefUpdateRequest, RefUpdateResponse, }; use session::Session; #[utoipa::path( get, path = "/api/repos/{namespace}/{repo}/git/refs", params( ("namespace" = String, Path, description = "Repository namespace"), ("repo" = String, Path, description = "Repository name"), ), responses( (status = 200, description = "List of refs", body = ApiResponse>), (status = 401, description = "Unauthorized", body = ApiResponse), (status = 404, description = "Not found", body = ApiResponse), ), tag = "Git" )] pub async fn git_ref_list( 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_ref_list(namespace, repo_name, query.into_inner(), &session) .await?; Ok(ApiResponse::ok(resp).to_response()) } #[utoipa::path( get, path = "/api/repos/{namespace}/{repo}/git/refs/{name}", params( ("namespace" = String, Path, description = "Repository namespace"), ("repo" = String, Path, description = "Repository name"), ("name" = String, Path, description = "Ref name"), ), responses( (status = 200, description = "Ref info", body = ApiResponse), (status = 401, description = "Unauthorized", body = ApiResponse), (status = 404, description = "Not found", body = ApiResponse), ), tag = "Git" )] pub async fn git_ref_get( service: web::Data, session: Session, path: web::Path<(String, String, String)>, ) -> Result { let (namespace, repo_name, name) = path.into_inner(); let resp = service .git_ref_get(namespace, repo_name, name, &session) .await?; Ok(ApiResponse::ok(resp).to_response()) } #[utoipa::path( post, path = "/api/repos/{namespace}/{repo}/git/refs", params( ("namespace" = String, Path, description = "Repository namespace"), ("repo" = String, Path, description = "Repository name"), ), request_body = RefCreateRequest, responses( (status = 200, description = "Ref created", body = ApiResponse), (status = 401, description = "Unauthorized", body = ApiResponse), (status = 404, description = "Not found", body = ApiResponse), ), tag = "Git" )] pub async fn git_ref_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_ref_create(namespace, repo_name, body.into_inner(), &session) .await?; Ok(ApiResponse::ok(resp).to_response()) } #[utoipa::path( delete, path = "/api/repos/{namespace}/{repo}/git/refs/{name}", params( ("namespace" = String, Path, description = "Repository namespace"), ("repo" = String, Path, description = "Repository name"), ("name" = String, Path, description = "Ref name"), ), responses( (status = 200, description = "Ref deleted", body = ApiResponse), (status = 401, description = "Unauthorized", body = ApiResponse), (status = 404, description = "Not found", body = ApiResponse), ), tag = "Git" )] pub async fn git_ref_delete( service: web::Data, session: Session, path: web::Path<(String, String, String)>, ) -> Result { let (namespace, repo_name, name) = path.into_inner(); let resp = service .git_ref_delete(namespace, repo_name, name, &session) .await?; Ok(ApiResponse::ok(resp).to_response()) } #[utoipa::path( patch, path = "/api/repos/{namespace}/{repo}/git/refs/rename", params( ("namespace" = String, Path, description = "Repository namespace"), ("repo" = String, Path, description = "Repository name"), ), responses( (status = 200, description = "Ref renamed", body = ApiResponse), (status = 401, description = "Unauthorized", body = ApiResponse), (status = 404, description = "Not found", body = ApiResponse), ), tag = "Git" )] pub async fn git_ref_rename( 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_ref_rename(namespace, repo_name, query.into_inner(), &session) .await?; Ok(ApiResponse::ok(resp).to_response()) } #[utoipa::path( put, path = "/api/repos/{namespace}/{repo}/git/refs", params( ("namespace" = String, Path, description = "Repository namespace"), ("repo" = String, Path, description = "Repository name"), ), request_body = RefUpdateRequest, responses( (status = 200, description = "Ref updated", body = ApiResponse), (status = 401, description = "Unauthorized", body = ApiResponse), (status = 404, description = "Not found", body = ApiResponse), ), tag = "Git" )] pub async fn git_ref_update( 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_ref_update(namespace, repo_name, body.into_inner(), &session) .await?; Ok(ApiResponse::ok(resp).to_response()) } #[utoipa::path( get, path = "/api/repos/{namespace}/{repo}/git/refs/{name}/exists", params( ("namespace" = String, Path, description = "Repository namespace"), ("repo" = String, Path, description = "Repository name"), ("name" = String, Path, description = "Ref name"), ), responses( (status = 200, description = "Ref exists check", body = ApiResponse), (status = 401, description = "Unauthorized", body = ApiResponse), (status = 404, description = "Not found", body = ApiResponse), ), tag = "Git" )] pub async fn git_ref_exists( service: web::Data, session: Session, path: web::Path<(String, String, String)>, ) -> Result { let (namespace, repo_name, name) = path.into_inner(); let resp = service .git_ref_exists(namespace, repo_name, name, &session) .await?; Ok(ApiResponse::ok(resp).to_response()) } #[utoipa::path( get, path = "/api/repos/{namespace}/{repo}/git/refs/{name}/target", params( ("namespace" = String, Path, description = "Repository namespace"), ("repo" = String, Path, description = "Repository name"), ("name" = String, Path, description = "Ref name"), ), responses( (status = 200, description = "Ref target", body = ApiResponse), (status = 401, description = "Unauthorized", body = ApiResponse), (status = 404, description = "Not found", body = ApiResponse), ), tag = "Git" )] pub async fn git_ref_target( service: web::Data, session: Session, path: web::Path<(String, String, String)>, ) -> Result { let (namespace, repo_name, name) = path.into_inner(); let resp = service .git_ref_target(namespace, repo_name, name, &session) .await?; Ok(ApiResponse::ok(resp).to_response()) }