use actix_web::{HttpResponse, web}; use serde::{Deserialize, Serialize}; use utoipa::{IntoParams, ToSchema}; use crate::api::response::{ApiErrorResponse, ApiResponse}; use crate::error::AppError; use crate::models::wiki::WikiPageRevision; use crate::service::AppService; use crate::session::Session; #[derive(Debug, Deserialize, IntoParams)] pub struct PathParams { /// Workspace name (unique identifier) pub workspace_name: String, /// Repository name (unique within the workspace) pub repo_name: String, /// Wiki page slug (URL-friendly identifier) pub slug: String, } #[derive(Debug, Deserialize, IntoParams)] pub struct QueryParams { /// Older version number to compare from pub old_version: i32, /// Newer version number to compare to pub new_version: i32, } /// Result of comparing two wiki page revisions #[derive(Debug, Serialize, Deserialize, ToSchema)] pub struct WikiCompareResult { /// The older revision being compared pub old: WikiPageRevision, /// The newer revision being compared pub new: WikiPageRevision, } /// Compare two wiki page revisions /// /// Compares two versions of a wiki page and returns both revisions. /// Requires read access to the repository. /// /// Returns the old and new revisions for client-side diff computation. /// The client can compute the diff between the two content snapshots. #[utoipa::path( get, path = "/api/v1/workspaces/{workspace_name}/repos/{repo_name}/wiki/{slug}/compare", tag = "Wiki", operation_id = "wikiCompareRevisions", params(PathParams, QueryParams), responses( (status = 200, description = "Revisions compared successfully. Returns old and new revision objects.", body = ApiResponse), (status = 400, description = "Invalid version numbers", body = ApiErrorResponse), (status = 401, description = "Authentication required or session expired", body = ApiErrorResponse), (status = 403, description = "Insufficient permissions to access this repository", body = ApiErrorResponse), (status = 404, description = "Wiki page, revisions, repository, or workspace not found", body = ApiErrorResponse), (status = 500, description = "Internal server error", body = ApiErrorResponse), ), security(("session_cookie" = [])) )] pub async fn compare_revisions( service: web::Data, session: Session, path: web::Path, query: web::Query, ) -> Result { let (old, new) = service .repo .wiki_compare_revisions( &session, &path.workspace_name, &path.repo_name, &path.slug, query.old_version, query.new_version, ) .await?; Ok(HttpResponse::Ok().json(ApiResponse::new(WikiCompareResult { old, new }))) }