use actix_web::{HttpResponse, web}; use crate::api::response::{ApiErrorResponse, ApiResponse}; use crate::error::AppError; use crate::models::workspaces::WorkspaceMember; use crate::service::AppService; use crate::service::workspace::members::AddMemberParams; use crate::session::Session; #[utoipa::path( post, path = "/api/v1/workspaces/{workspace_name}/members", tag = "Workspaces", operation_id = "workspaceAddMember", summary = "Add a member", description = "Add a user to a workspace. Requires admin role. Cannot add members with role equal to or higher than the caller.", params( ("workspace_name" = String, Path, description = "Workspace name.") ), request_body( content = AddMemberParams, description = "User ID and optional role.", content_type = "application/json" ), responses( (status = 200, description = "Member added.", body = ApiResponse), (status = 400, description = "Cannot add owner, invalid role, or member invites disabled.", body = ApiErrorResponse), (status = 401, description = "Unauthenticated or insufficient role.", body = ApiErrorResponse), (status = 409, description = "User is already a member.", body = ApiErrorResponse), (status = 500, description = "Database transaction failed.", body = ApiErrorResponse) ) )] pub async fn handle( service: web::Data, session: Session, path: web::Path, params: web::Json, ) -> Result { let ws = service.workspace.find_workspace_by_name(&path).await?; let data = service .workspace .workspace_add_member(&session, &ws, params.into_inner()) .await?; Ok(HttpResponse::Ok().json(ApiResponse::new(data))) }