Change filter type to accept property comparators too

Signed-off-by: trivernis <trivernis@protonmail.com>
pull/4/head
trivernis 3 years ago
parent 717de6684a
commit ed28bc68c8

@ -1,6 +1,6 @@
[package] [package]
name = "mediarepo-api" name = "mediarepo-api"
version = "0.25.0" version = "0.26.0"
edition = "2018" edition = "2018"
license = "gpl-3" license = "gpl-3"

@ -2,9 +2,10 @@ use crate::client_api::error::ApiResult;
use crate::client_api::IPCApi; use crate::client_api::IPCApi;
use crate::types::files::{ use crate::types::files::{
AddFileRequestHeader, FileBasicDataResponse, FileMetadataResponse, FileOSMetadata, AddFileRequestHeader, FileBasicDataResponse, FileMetadataResponse, FileOSMetadata,
FilterExpression, FindFilesRequest, GetFileThumbnailOfSizeRequest, GetFileThumbnailsRequest, GetFileThumbnailOfSizeRequest, GetFileThumbnailsRequest, ReadFileRequest,
ReadFileRequest, SortKey, ThumbnailMetadataResponse, UpdateFileNameRequest, ThumbnailMetadataResponse, UpdateFileNameRequest,
}; };
use crate::types::filtering::{FilterExpression, FindFilesRequest, SortKey};
use crate::types::identifier::FileIdentifier; use crate::types::identifier::FileIdentifier;
use async_trait::async_trait; use async_trait::async_trait;
use bromine::context::{PoolGuard, PooledContext}; use bromine::context::{PoolGuard, PooledContext};

@ -2,9 +2,9 @@ use crate::tauri_plugin::commands::{ApiAccess, BufferAccess};
use crate::tauri_plugin::error::PluginResult; use crate::tauri_plugin::error::PluginResult;
use crate::tauri_plugin::utils::system_time_to_naive_date_time; use crate::tauri_plugin::utils::system_time_to_naive_date_time;
use crate::types::files::{ use crate::types::files::{
FileBasicDataResponse, FileMetadataResponse, FileOSMetadata, FilterExpression, SortKey, FileBasicDataResponse, FileMetadataResponse, FileOSMetadata, ThumbnailMetadataResponse,
ThumbnailMetadataResponse,
}; };
use crate::types::filtering::{FilterExpression, SortKey};
use crate::types::identifier::FileIdentifier; use crate::types::identifier::FileIdentifier;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::path::PathBuf; use std::path::PathBuf;

@ -1,9 +1,11 @@
use crate::types::files::{ use crate::types::files::GetFileThumbnailOfSizeRequest;
FilterExpression, GetFileThumbnailOfSizeRequest, SortDirection, SortKey, TagQuery, use crate::types::filtering::{
FilterExpression, SortDirection, SortKey, TagQuery, ValueComparator,
}; };
use crate::types::identifier::FileIdentifier; use crate::types::identifier::FileIdentifier;
use bromine::payload::DynamicSerializer; use bromine::payload::DynamicSerializer;
use bromine::prelude::IPCResult; use bromine::prelude::IPCResult;
use chrono::NaiveDateTime;
use serde::de::DeserializeOwned; use serde::de::DeserializeOwned;
use serde::Serialize; use serde::Serialize;
@ -45,6 +47,15 @@ fn it_serializes_sort_keys() {
test_serialization(SortKey::FileName(SortDirection::Descending)).unwrap(); 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<T: Serialize + DeserializeOwned>(data: T) -> IPCResult<()> { fn test_serialization<T: Serialize + DeserializeOwned>(data: T) -> IPCResult<()> {
let serializer = DynamicSerializer::first_available(); let serializer = DynamicSerializer::first_available();
let bytes = serializer.serialize(data)?; let bytes = serializer.serialize(data)?;

@ -1,6 +1,7 @@
use crate::types::identifier::FileIdentifier; use crate::types::identifier::FileIdentifier;
use chrono::NaiveDateTime; use chrono::NaiveDateTime;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::fmt::Debug;
#[derive(Clone, Debug, Serialize, Deserialize)] #[derive(Clone, Debug, Serialize, Deserialize)]
pub struct ReadFileRequest { pub struct ReadFileRequest {
@ -29,50 +30,6 @@ pub struct GetFilesTagsRequest {
pub cds: Vec<String>, pub cds: Vec<String>,
} }
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct FindFilesRequest {
pub filters: Vec<FilterExpression>,
pub sort_expression: Vec<SortKey>,
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub enum FilterExpression {
OrExpression(Vec<TagQuery>),
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)] #[derive(Clone, Debug, Serialize, Deserialize)]
pub struct FileBasicDataResponse { pub struct FileBasicDataResponse {
pub id: i64, pub id: i64,

@ -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<FilterExpression>,
pub sort_expression: Vec<SortKey>,
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub enum FilterExpression {
OrExpression(Vec<FilterQuery>),
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<u64>),
ImportedTime(ValueComparator<NaiveDateTime>),
ChangedTime(ValueComparator<NaiveDateTime>),
CreatedTime(ValueComparator<NaiveDateTime>),
TagCount(ValueComparator<u64>),
Cd(String),
Id(i64),
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub enum ValueComparator<T> {
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 {}

@ -1,4 +1,5 @@
pub mod files; pub mod files;
pub mod filtering;
pub mod identifier; pub mod identifier;
pub mod jobs; pub mod jobs;
pub mod misc; pub mod misc;

Loading…
Cancel
Save