use actix_web::{HttpResponse, web}; use crate::api::response::{ApiEmptyResponse, ApiErrorResponse}; use crate::error::AppError; use crate::service::AppService; use crate::session::Session; #[utoipa::path( post, path = "/api/v1/workspaces/{workspace_name}/leave", tag = "Workspaces", operation_id = "workspaceLeave", summary = "Leave a workspace", description = "Remove the current user from the workspace. The owner cannot leave; transfer ownership first.", params( ("workspace_name" = String, Path, description = "Workspace name.") ), responses( (status = 200, description = "Left the workspace.", body = ApiEmptyResponse), (status = 400, description = "Owner cannot leave.", body = ApiErrorResponse), (status = 401, description = "Unauthenticated or not a member.", body = ApiErrorResponse), (status = 500, description = "Database transaction failed.", body = ApiErrorResponse) ) )] pub async fn handle( service: web::Data, session: Session, path: web::Path, ) -> Result { let ws = service.workspace.find_workspace_by_name(&path).await?; service.workspace.workspace_leave(&session, &ws).await?; Ok(HttpResponse::Ok().json(ApiEmptyResponse::ok("left workspace"))) }