gitdataai/libs/api/git/init.rs
ZhenYi 14f6e1e500 feat(core): initialize project with access control and AI integration
- Add gitignore and prettier configuration files for project scaffolding
- Implement room access control service with project member verification
- Create user access key management with CRUD operations and activity logging
- Add accordion UI component for frontend expandable sections
- Implement room AI configuration with list, upsert, and delete operations
- Add AI event types for agent join/leave/status change tracking
- Create streaming AI processing services for mode and react patterns
- Build room AI service with model detection and idempotency handling
- Integrate chat service orchestration for AI message processing
- Add typing indicators and stream cancellation for AI interactions
- Implement mention parsing and context extraction for AI agents
2026-05-03 06:04:31 +08:00

118 lines
4.0 KiB
Rust

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<service::git::init::GitInitResponse>),
(status = 401, description = "Unauthorized", body = ApiResponse<crate::error::ApiError>),
(status = 404, description = "Not found", body = ApiResponse<crate::error::ApiError>),
),
tag = "Git"
)]
pub async fn git_init_bare(
service: web::Data<AppService>,
session: Session,
body: web::Json<GitInitRequest>,
) -> Result<HttpResponse, ApiError> {
let resp = service.git_init_bare(body.into_inner(), &session).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<service::git::init::GitInitResponse>),
(status = 401, description = "Unauthorized", body = ApiResponse<crate::error::ApiError>),
(status = 404, description = "Not found", body = ApiResponse<crate::error::ApiError>),
),
tag = "Git"
)]
pub async fn git_open(
service: web::Data<AppService>,
session: Session,
path: web::Path<String>,
) -> Result<HttpResponse, ApiError> {
let resp = service.git_open(path.into_inner(), &session).await?;
Ok(ApiResponse::ok(resp).to_response())
}
#[utoipa::path(
get,
path = "/api/git/open/{path}/bare",
params(
("path" = String, Path, description = "Repository path"),
),
responses(
(status = 200, description = "Open bare repository", body = ApiResponse<service::git::init::GitInitResponse>),
(status = 401, description = "Unauthorized", body = ApiResponse<crate::error::ApiError>),
(status = 404, description = "Not found", body = ApiResponse<crate::error::ApiError>),
),
tag = "Git"
)]
pub async fn git_open_bare(
service: web::Data<AppService>,
session: Session,
path: web::Path<String>,
) -> Result<HttpResponse, ApiError> {
let resp = service.git_open_bare(path.into_inner(), &session).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<bool>),
(status = 401, description = "Unauthorized", body = ApiResponse<crate::error::ApiError>),
(status = 404, description = "Not found", body = ApiResponse<crate::error::ApiError>),
),
tag = "Git"
)]
pub async fn git_is_repo(
service: web::Data<AppService>,
session: Session,
path: web::Path<String>,
) -> Result<HttpResponse, ApiError> {
let resp = service.git_is_repo(path.into_inner(), &session).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<String>),
(status = 401, description = "Unauthorized", body = ApiResponse<crate::error::ApiError>),
(status = 404, description = "Not found", body = ApiResponse<crate::error::ApiError>),
),
tag = "Git"
)]
pub async fn git_repo_path(
service: web::Data<AppService>,
session: Session,
path: web::Path<(String, String)>,
) -> Result<HttpResponse, ApiError> {
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 })))
}