use actix_web::{HttpResponse, web}; use serde::Deserialize; use utoipa::IntoParams; 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 { /// Maximum number of revisions to return (default: 50, max: 100) pub limit: Option, /// Number of revisions to skip for pagination (default: 0) pub offset: Option, } /// List wiki page revisions /// /// Returns a paginated list of all revisions for a wiki page, sorted by version (newest first). /// Requires read access to the repository. /// /// Each revision includes the full content snapshot at that version, /// the editor who made the change, and an optional commit message. #[utoipa::path( get, path = "/api/v1/workspaces/{workspace_name}/repos/{repo_name}/wiki/{slug}/revisions", tag = "Wiki", operation_id = "wikiListRevisions", params(PathParams, QueryParams), responses( (status = 200, description = "Revisions listed successfully.", body = ApiResponse>), (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, repository, or workspace not found", body = ApiErrorResponse), (status = 500, description = "Internal server error", body = ApiErrorResponse), ), security(("session_cookie" = [])) )] pub async fn list_revisions( service: web::Data, session: Session, path: web::Path, query: web::Query, ) -> Result { let revisions = service .repo .wiki_get_revisions( &session, &path.workspace_name, &path.repo_name, &path.slug, query.limit.unwrap_or(50), query.offset.unwrap_or(0), ) .await?; Ok(HttpResponse::Ok().json(ApiResponse::new(revisions))) }