Files
appks/api/workspace/accept_invitation.rs
zhenyi dca717be10 refactor(workspace): pass workspace object instead of id to service methods
- Replace workspace_id parameter with Workspace object reference in all workspace service methods
- Remove redundant find_workspace_by_id calls that were duplicated in each method
- Update all method signatures across approval, audit, billing, branding, core, settings and stats modules
- Modify SQL queries to bind ws.id instead of separate workspace_id parameter
- Add Workspace import to all affected modules
- Adjust method calls in API handlers to pass workspace object instead of id
- Consolidate workspace retrieval logic to single location per operation flow
2026-06-07 18:44:01 +08:00

46 lines
1.7 KiB
Rust

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<WorkspaceInvitation>),
(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<AppService>,
session: Session,
params: web::Json<AcceptInvitationRequest>,
) -> Result<HttpResponse, AppError> {
let data = service
.workspace
.workspace_accept_invitation(&session, &params.token)
.await?;
Ok(HttpResponse::Ok().json(ApiResponse::new(data)))
}