pinakes-server: add utoipa annotations to all routes; fix tests

Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: I28cf5b7b7cff8e90e123d624d97cf9656a6a6964
This commit is contained in:
raf 2026-03-21 02:17:55 +03:00
commit 9d58927cb4
Signed by: NotAShelf
GPG key ID: 29D95B64378DB4BF
60 changed files with 3493 additions and 242 deletions

View file

@ -34,7 +34,7 @@ pub fn relativize_path(full_path: &Path, roots: &[PathBuf]) -> String {
full_path.to_string_lossy().into_owned()
}
#[derive(Debug, Serialize)]
#[derive(Debug, Serialize, utoipa::ToSchema)]
pub struct MediaResponse {
pub id: String,
pub path: String,
@ -50,6 +50,7 @@ pub struct MediaResponse {
pub duration_secs: Option<f64>,
pub description: Option<String>,
pub has_thumbnail: bool,
#[schema(value_type = Object)]
pub custom_fields: FxHashMap<String, CustomFieldResponse>,
// Photo-specific metadata
@ -67,24 +68,25 @@ pub struct MediaResponse {
pub links_extracted_at: Option<DateTime<Utc>>,
}
#[derive(Debug, Serialize)]
#[derive(Debug, Serialize, utoipa::ToSchema)]
pub struct CustomFieldResponse {
pub field_type: String,
pub value: String,
}
#[derive(Debug, Deserialize)]
#[derive(Debug, Deserialize, utoipa::ToSchema)]
pub struct ImportRequest {
#[schema(value_type = String)]
pub path: PathBuf,
}
#[derive(Debug, Serialize)]
#[derive(Debug, Serialize, utoipa::ToSchema)]
pub struct ImportResponse {
pub media_id: String,
pub was_duplicate: bool,
}
#[derive(Debug, Deserialize)]
#[derive(Debug, Deserialize, utoipa::ToSchema)]
pub struct UpdateMediaRequest {
pub title: Option<String>,
pub artist: Option<String>,
@ -95,56 +97,60 @@ pub struct UpdateMediaRequest {
}
// File Management
#[derive(Debug, Deserialize)]
#[derive(Debug, Deserialize, utoipa::ToSchema)]
pub struct RenameMediaRequest {
pub new_name: String,
}
#[derive(Debug, Deserialize)]
#[derive(Debug, Deserialize, utoipa::ToSchema)]
pub struct MoveMediaRequest {
#[schema(value_type = String)]
pub destination: PathBuf,
}
#[derive(Debug, Deserialize)]
#[derive(Debug, Deserialize, utoipa::ToSchema)]
pub struct BatchMoveRequest {
pub media_ids: Vec<Uuid>,
#[schema(value_type = String)]
pub destination: PathBuf,
}
#[derive(Debug, Serialize)]
#[derive(Debug, Serialize, utoipa::ToSchema)]
pub struct TrashResponse {
pub items: Vec<MediaResponse>,
pub total_count: u64,
}
#[derive(Debug, Serialize)]
#[derive(Debug, Serialize, utoipa::ToSchema)]
pub struct TrashInfoResponse {
pub count: u64,
}
#[derive(Debug, Serialize)]
#[derive(Debug, Serialize, utoipa::ToSchema)]
pub struct EmptyTrashResponse {
pub deleted_count: u64,
}
// Enhanced Import
#[derive(Debug, Deserialize)]
#[derive(Debug, Deserialize, utoipa::ToSchema)]
pub struct ImportWithOptionsRequest {
#[schema(value_type = String)]
pub path: PathBuf,
pub tag_ids: Option<Vec<Uuid>>,
pub new_tags: Option<Vec<String>>,
pub collection_id: Option<Uuid>,
}
#[derive(Debug, Deserialize)]
#[derive(Debug, Deserialize, utoipa::ToSchema)]
pub struct BatchImportRequest {
#[schema(value_type = Vec<String>)]
pub paths: Vec<PathBuf>,
pub tag_ids: Option<Vec<Uuid>>,
pub new_tags: Option<Vec<String>>,
pub collection_id: Option<Uuid>,
}
#[derive(Debug, Serialize)]
#[derive(Debug, Serialize, utoipa::ToSchema)]
pub struct BatchImportResponse {
pub results: Vec<BatchImportItemResult>,
pub total: usize,
@ -153,7 +159,7 @@ pub struct BatchImportResponse {
pub errors: usize,
}
#[derive(Debug, Serialize)]
#[derive(Debug, Serialize, utoipa::ToSchema)]
pub struct BatchImportItemResult {
pub path: String,
pub media_id: Option<String>,
@ -161,22 +167,23 @@ pub struct BatchImportItemResult {
pub error: Option<String>,
}
#[derive(Debug, Deserialize)]
#[derive(Debug, Deserialize, utoipa::ToSchema)]
pub struct DirectoryImportRequest {
#[schema(value_type = String)]
pub path: PathBuf,
pub tag_ids: Option<Vec<Uuid>>,
pub new_tags: Option<Vec<String>>,
pub collection_id: Option<Uuid>,
}
#[derive(Debug, Serialize)]
#[derive(Debug, Serialize, utoipa::ToSchema)]
pub struct DirectoryPreviewResponse {
pub files: Vec<DirectoryPreviewFile>,
pub total_count: usize,
pub total_size: u64,
}
#[derive(Debug, Serialize)]
#[derive(Debug, Serialize, utoipa::ToSchema)]
pub struct DirectoryPreviewFile {
pub path: String,
pub file_name: String,
@ -185,7 +192,7 @@ pub struct DirectoryPreviewFile {
}
// Custom Fields
#[derive(Debug, Deserialize)]
#[derive(Debug, Deserialize, utoipa::ToSchema)]
pub struct SetCustomFieldRequest {
pub name: String,
pub field_type: String,
@ -193,7 +200,7 @@ pub struct SetCustomFieldRequest {
}
// Media update extended
#[derive(Debug, Deserialize)]
#[derive(Debug, Deserialize, utoipa::ToSchema)]
pub struct UpdateMediaFullRequest {
pub title: Option<String>,
pub artist: Option<String>,
@ -204,26 +211,26 @@ pub struct UpdateMediaFullRequest {
}
// Search with sort
#[derive(Debug, Serialize)]
#[derive(Debug, Serialize, utoipa::ToSchema)]
pub struct MediaCountResponse {
pub count: u64,
}
// Duplicates
#[derive(Debug, Serialize)]
#[derive(Debug, Serialize, utoipa::ToSchema)]
pub struct DuplicateGroupResponse {
pub content_hash: String,
pub items: Vec<MediaResponse>,
}
// Open
#[derive(Debug, Deserialize)]
#[derive(Debug, Deserialize, utoipa::ToSchema)]
pub struct OpenRequest {
pub media_id: Uuid,
}
// Upload
#[derive(Debug, Serialize)]
#[derive(Debug, Serialize, utoipa::ToSchema)]
pub struct UploadResponse {
pub media_id: String,
pub content_hash: String,
@ -242,7 +249,7 @@ impl From<pinakes_core::model::UploadResult> for UploadResponse {
}
}
#[derive(Debug, Serialize)]
#[derive(Debug, Serialize, utoipa::ToSchema)]
pub struct ManagedStorageStatsResponse {
pub total_blobs: u64,
pub total_size_bytes: u64,
@ -368,12 +375,12 @@ mod tests {
}
// Watch progress
#[derive(Debug, Deserialize)]
#[derive(Debug, Deserialize, utoipa::ToSchema)]
pub struct WatchProgressRequest {
pub progress_secs: f64,
}
#[derive(Debug, Serialize)]
#[derive(Debug, Serialize, utoipa::ToSchema)]
pub struct WatchProgressResponse {
pub progress_secs: f64,
}