Files
appks/api/repo/accept_invitation.rs
zhenyi 4028f0d943 refactor(api): reorder imports and update code formatting across repository endpoints
- Reordered actix-web imports to standardize import order
- Reordered crate module imports to follow alphabetical ordering
- Updated function calls to use multi-line formatting for better readability
- Standardized blank lines around documentation comments
- Applied consistent formatting to response handling methods
- Normalized import organization across all repository-related API files
- Improved code consistency and maintainability through standardized formatting
- Applied formatting updates to all repository endpoint implementations
2026-06-07 19:41:33 +08:00

62 lines
2.2 KiB
Rust

use actix_web::{HttpResponse, web};
use serde::Deserialize;
use utoipa::ToSchema;
use crate::api::response::{ApiErrorResponse, ApiResponse};
use crate::error::AppError;
use crate::models::repos::RepoInvitation;
use crate::service::AppService;
use crate::session::Session;
#[derive(Debug, Deserialize, ToSchema)]
pub struct AcceptInvitationParams {
/// Invitation token (received via email)
pub token: String,
}
/// Accept a repository invitation
///
/// Accepts a pending repository invitation using the token received via email.
/// Requires authentication and a verified email address matching the invitation.
///
/// Effects:
/// - User is added as a repository member with the invited role
/// - User is added to the workspace if not already a member
/// - Invitation is marked as accepted
///
/// Returns the accepted invitation with full metadata.
#[utoipa::path(
post,
path = "/api/v1/repos/invitations/accept",
tag = "Repos",
operation_id = "repoAcceptInvitation",
request_body(
content = AcceptInvitationParams,
description = "Invitation acceptance parameters",
content_type = "application/json"
),
responses(
(status = 200, description = "Invitation accepted successfully. User is now a member of the repository.", body = ApiResponse<RepoInvitation>),
(status = 400, description = "Invalid or expired token, or email doesn't match invitation", body = ApiErrorResponse),
(status = 401, description = "Authentication required or session expired", body = ApiErrorResponse),
(status = 404, description = "Invitation not found", body = ApiErrorResponse),
(status = 409, description = "User is already a member of this repository", body = ApiErrorResponse),
(status = 500, description = "Internal server error", body = ApiErrorResponse),
),
security(
("session_cookie" = [])
)
)]
pub async fn accept_invitation(
service: web::Data<AppService>,
session: Session,
params: web::Json<AcceptInvitationParams>,
) -> Result<HttpResponse, AppError> {
let invitation = service
.repo
.repo_accept_invitation(&session, &params.token)
.await?;
Ok(HttpResponse::Ok().json(ApiResponse::new(invitation)))
}