use actix_web::{HttpResponse, web}; use serde::{Deserialize, Serialize}; use crate::api::response::{ApiErrorResponse, ApiResponse}; use crate::error::AppError; use crate::models::workspaces::WorkspaceInvitation; use crate::service::AppService; use crate::session::Session; #[derive(Deserialize, Serialize, utoipa::ToSchema)] pub struct AcceptInvitationRequest { /// The plaintext invitation token from the email link. pub token: String, } #[utoipa::path( post, path = "/api/v1/workspaces/invitations/accept", tag = "Workspaces", operation_id = "workspaceAcceptInvitation", summary = "Accept an invitation", description = "Accept a workspace invitation using the token from the invitation email. The authenticated user's verified email must match the invited email.", request_body( content = AcceptInvitationRequest, description = "Invitation token.", content_type = "application/json" ), responses( (status = 200, description = "Invitation accepted and user added as a member.", body = ApiResponse), (status = 400, description = "Invalid or expired invitation, or already a member.", body = ApiErrorResponse), (status = 401, description = "Unauthenticated or email mismatch.", body = ApiErrorResponse), (status = 500, description = "Database transaction failed.", body = ApiErrorResponse) ) )] pub async fn handle( service: web::Data, session: Session, params: web::Json, ) -> Result { let data = service .workspace .workspace_accept_invitation(&session, ¶ms.token) .await?; Ok(HttpResponse::Ok().json(ApiResponse::new(data))) }