use actix_web::{HttpResponse, web}; use serde::Deserialize; use utoipa::IntoParams; use crate::api::response::{ApiErrorResponse, ApiResponse}; use crate::error::AppError; use crate::service::AppService; use crate::session::Session; #[derive(Debug, Deserialize, IntoParams)] pub struct PathParams { /// Token ID (UUID) pub token_id: uuid::Uuid, } /// Revoke a personal access token /// /// Immediately revokes a personal access token belonging to the authenticated user. /// Requires authentication. /// /// Effects: /// - Token is marked as revoked and can no longer be used /// - All API calls using this token will fail with 401 Unauthorized /// - Revoked tokens remain visible in token list for audit purposes /// /// Returns success message on completion. #[utoipa::path( delete, path = "/api/v1/user/security/tokens/{token_id}", tag = "User", operation_id = "userRevokeToken", params(PathParams), responses( (status = 200, description = "Personal access token revoked successfully.", body = ApiResponse), (status = 401, description = "Authentication required or session expired", body = ApiErrorResponse), (status = 404, description = "Token not found or already revoked", body = ApiErrorResponse), (status = 500, description = "Internal server error", body = ApiErrorResponse), ), security( ("session_cookie" = []) ) )] pub async fn revoke_token( service: web::Data, session: Session, path: web::Path, ) -> Result { service .user .user_revoke_personal_access_token(&session, path.token_id) .await?; Ok(HttpResponse::Ok().json(ApiResponse::new( "Personal access token revoked successfully".to_string(), ))) }