use actix_web::{web, HttpResponse}; use serde::Deserialize; use utoipa::ToSchema; use crate::api::response::{ApiResponse, ApiErrorResponse}; 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), (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, session: Session, params: web::Json, ) -> Result { let invitation = service .repo .repo_accept_invitation(&session, ¶ms.token) .await?; Ok(HttpResponse::Ok().json(ApiResponse::new(invitation))) }