cec6dce955
- Add git operation endpoints: archive, compare branches, diff, tree, repository extras - Add repo endpoints: contributors, delete fork, get branch/commit status/deploy key/invitation/member/release/tag/webhook, topics, release assets, webhook deliveries/retry - Add PR endpoints: review requests, templates - Add user endpoints: block/unblock, follow/unfollow, presence, personal access tokens, account restore - Add workspace endpoints: billing history, approvals, domains, integrations, invitations, members, webhooks, restore - Add internal API, notification API, IM API modules - Update route configuration and OpenAPI spec
59 lines
1.8 KiB
Rust
59 lines
1.8 KiB
Rust
use actix_web::{HttpResponse, web};
|
|
use serde::Deserialize;
|
|
use uuid::Uuid;
|
|
|
|
use crate::api::response::{ApiErrorResponse, ApiResponse};
|
|
use crate::error::AppError;
|
|
use crate::models::base_info::resolve_users;
|
|
use crate::models::workspaces::WorkspaceDetail;
|
|
use crate::service::AppService;
|
|
use crate::session::Session;
|
|
|
|
#[derive(Deserialize, utoipa::IntoParams)]
|
|
pub struct ListQuery {
|
|
pub limit: Option<i64>,
|
|
pub offset: Option<i64>,
|
|
}
|
|
|
|
#[utoipa::path(
|
|
get,
|
|
path = "/api/v1/workspaces",
|
|
tag = "Workspaces",
|
|
operation_id = "workspaceList",
|
|
summary = "List accessible workspaces",
|
|
description = "Return workspaces owned by, joined by, or publicly accessible to the current user.",
|
|
params(ListQuery),
|
|
responses(
|
|
(status = 200, description = "List of workspaces.", body = ApiResponse<Vec<WorkspaceDetail>>),
|
|
(status = 401, description = "Unauthenticated.", body = ApiErrorResponse),
|
|
(status = 500, description = "Database read failed.", body = ApiErrorResponse)
|
|
)
|
|
)]
|
|
pub async fn handle(
|
|
service: web::Data<AppService>,
|
|
session: Session,
|
|
query: web::Query<ListQuery>,
|
|
) -> Result<HttpResponse, AppError> {
|
|
let data = service
|
|
.workspace
|
|
.workspace_list(
|
|
&session,
|
|
query.limit.unwrap_or(50),
|
|
query.offset.unwrap_or(0),
|
|
)
|
|
.await?;
|
|
|
|
let db = &service.ctx.db;
|
|
let owner_ids: Vec<Uuid> = data.iter().map(|w| w.owner_id).collect();
|
|
let users = resolve_users(db, &owner_ids).await?;
|
|
let details: Vec<WorkspaceDetail> = data
|
|
.into_iter()
|
|
.map(|w| {
|
|
let owner = users.get(&w.owner_id).cloned().unwrap_or_default();
|
|
w.into_detail(owner)
|
|
})
|
|
.collect();
|
|
|
|
Ok(HttpResponse::Ok().json(ApiResponse::new(details)))
|
|
}
|