diff --git a/mediarepo-api/Cargo.toml b/mediarepo-api/Cargo.toml index 7876ed4..928d3cc 100644 --- a/mediarepo-api/Cargo.toml +++ b/mediarepo-api/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "mediarepo-api" -version = "0.25.0" +version = "0.26.0" edition = "2018" license = "gpl-3" diff --git a/mediarepo-api/src/client_api/file.rs b/mediarepo-api/src/client_api/file.rs index 7ed1369..1ef4a2f 100644 --- a/mediarepo-api/src/client_api/file.rs +++ b/mediarepo-api/src/client_api/file.rs @@ -2,9 +2,10 @@ use crate::client_api::error::ApiResult; use crate::client_api::IPCApi; use crate::types::files::{ AddFileRequestHeader, FileBasicDataResponse, FileMetadataResponse, FileOSMetadata, - FilterExpression, FindFilesRequest, GetFileThumbnailOfSizeRequest, GetFileThumbnailsRequest, - ReadFileRequest, SortKey, ThumbnailMetadataResponse, UpdateFileNameRequest, + GetFileThumbnailOfSizeRequest, GetFileThumbnailsRequest, ReadFileRequest, + ThumbnailMetadataResponse, UpdateFileNameRequest, }; +use crate::types::filtering::{FilterExpression, FindFilesRequest, SortKey}; use crate::types::identifier::FileIdentifier; use async_trait::async_trait; use bromine::context::{PoolGuard, PooledContext}; diff --git a/mediarepo-api/src/tauri_plugin/commands/file.rs b/mediarepo-api/src/tauri_plugin/commands/file.rs index 697f429..61ae057 100644 --- a/mediarepo-api/src/tauri_plugin/commands/file.rs +++ b/mediarepo-api/src/tauri_plugin/commands/file.rs @@ -2,9 +2,9 @@ use crate::tauri_plugin::commands::{ApiAccess, BufferAccess}; use crate::tauri_plugin::error::PluginResult; use crate::tauri_plugin::utils::system_time_to_naive_date_time; use crate::types::files::{ - FileBasicDataResponse, FileMetadataResponse, FileOSMetadata, FilterExpression, SortKey, - ThumbnailMetadataResponse, + FileBasicDataResponse, FileMetadataResponse, FileOSMetadata, ThumbnailMetadataResponse, }; +use crate::types::filtering::{FilterExpression, SortKey}; use crate::types::identifier::FileIdentifier; use serde::{Deserialize, Serialize}; use std::path::PathBuf; diff --git a/mediarepo-api/src/test/test_type_serialization.rs b/mediarepo-api/src/test/test_type_serialization.rs index d183d46..56ecb83 100644 --- a/mediarepo-api/src/test/test_type_serialization.rs +++ b/mediarepo-api/src/test/test_type_serialization.rs @@ -1,9 +1,11 @@ -use crate::types::files::{ - FilterExpression, GetFileThumbnailOfSizeRequest, SortDirection, SortKey, TagQuery, +use crate::types::files::GetFileThumbnailOfSizeRequest; +use crate::types::filtering::{ + FilterExpression, SortDirection, SortKey, TagQuery, ValueComparator, }; use crate::types::identifier::FileIdentifier; use bromine::payload::DynamicSerializer; use bromine::prelude::IPCResult; +use chrono::NaiveDateTime; use serde::de::DeserializeOwned; use serde::Serialize; @@ -45,6 +47,15 @@ fn it_serializes_sort_keys() { test_serialization(SortKey::FileName(SortDirection::Descending)).unwrap(); } +#[test] +fn it_serializes_value_comparators() { + test_serialization(ValueComparator::Between(( + NaiveDateTime::from_timestamp(100, 0), + NaiveDateTime::from_timestamp(100, 10), + ))) + .unwrap(); +} + fn test_serialization(data: T) -> IPCResult<()> { let serializer = DynamicSerializer::first_available(); let bytes = serializer.serialize(data)?; diff --git a/mediarepo-api/src/types/files.rs b/mediarepo-api/src/types/files.rs index 3a5c480..7a67630 100644 --- a/mediarepo-api/src/types/files.rs +++ b/mediarepo-api/src/types/files.rs @@ -1,6 +1,7 @@ use crate::types::identifier::FileIdentifier; use chrono::NaiveDateTime; use serde::{Deserialize, Serialize}; +use std::fmt::Debug; #[derive(Clone, Debug, Serialize, Deserialize)] pub struct ReadFileRequest { @@ -29,50 +30,6 @@ pub struct GetFilesTagsRequest { pub cds: Vec, } -#[derive(Clone, Debug, Serialize, Deserialize)] -pub struct FindFilesRequest { - pub filters: Vec, - pub sort_expression: Vec, -} - -#[derive(Clone, Debug, Serialize, Deserialize)] -pub enum FilterExpression { - OrExpression(Vec), - Query(TagQuery), -} - -#[derive(Clone, Debug, Serialize, Deserialize)] -pub struct TagQuery { - pub negate: bool, - pub tag: String, -} - -#[derive(Clone, Debug, Serialize, Deserialize)] -pub enum SortKey { - Namespace(SortNamespace), - FileName(SortDirection), - FileSize(SortDirection), - FileImportedTime(SortDirection), - FileCreatedTime(SortDirection), - FileChangeTime(SortDirection), - FileType(SortDirection), - NumTags(SortDirection), -} - -#[derive(Clone, Debug, Serialize, Deserialize)] -pub struct SortNamespace { - pub name: String, - pub direction: SortDirection, -} - -#[derive(Clone, Debug, Serialize, Deserialize, Ord, PartialOrd, PartialEq)] -pub enum SortDirection { - Ascending, - Descending, -} - -impl Eq for SortDirection {} - #[derive(Clone, Debug, Serialize, Deserialize)] pub struct FileBasicDataResponse { pub id: i64, diff --git a/mediarepo-api/src/types/filtering.rs b/mediarepo-api/src/types/filtering.rs new file mode 100644 index 0000000..916db73 --- /dev/null +++ b/mediarepo-api/src/types/filtering.rs @@ -0,0 +1,73 @@ +use crate::types::files::FileStatus; +use chrono::NaiveDateTime; +use serde::{Deserialize, Serialize}; + +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct FindFilesRequest { + pub filters: Vec, + pub sort_expression: Vec, +} + +#[derive(Clone, Debug, Serialize, Deserialize)] +pub enum FilterExpression { + OrExpression(Vec), + Query(FilterQuery), +} + +#[derive(Clone, Debug, Serialize, Deserialize)] +pub enum FilterQuery { + Tag(TagQuery), + Property(PropertyQuery), +} + +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct TagQuery { + pub negate: bool, + pub tag: String, +} + +#[derive(Clone, Debug, Serialize, Deserialize)] +pub enum PropertyQuery { + Status(FileStatus), + FileSize(ValueComparator), + ImportedTime(ValueComparator), + ChangedTime(ValueComparator), + CreatedTime(ValueComparator), + TagCount(ValueComparator), + Cd(String), + Id(i64), +} + +#[derive(Clone, Debug, Serialize, Deserialize)] +pub enum ValueComparator { + Less(T), + Equal(T), + Greater(T), + Between((T, T)), +} + +#[derive(Clone, Debug, Serialize, Deserialize)] +pub enum SortKey { + Namespace(SortNamespace), + FileName(SortDirection), + FileSize(SortDirection), + FileImportedTime(SortDirection), + FileCreatedTime(SortDirection), + FileChangeTime(SortDirection), + FileType(SortDirection), + NumTags(SortDirection), +} + +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct SortNamespace { + pub name: String, + pub direction: SortDirection, +} + +#[derive(Clone, Debug, Serialize, Deserialize, Ord, PartialOrd, PartialEq)] +pub enum SortDirection { + Ascending, + Descending, +} + +impl Eq for SortDirection {} diff --git a/mediarepo-api/src/types/mod.rs b/mediarepo-api/src/types/mod.rs index 0c05de4..f76121e 100644 --- a/mediarepo-api/src/types/mod.rs +++ b/mediarepo-api/src/types/mod.rs @@ -1,4 +1,5 @@ pub mod files; +pub mod filtering; pub mod identifier; pub mod jobs; pub mod misc;