commands: use real Filter type

This commit is contained in:
Oystein Kristoffer Tveit 2024-12-13 17:05:08 +01:00
parent 2fb97a9964
commit 4f6392e376
Signed by: oysteikt
GPG Key ID: 9F2F7D8250F35146
6 changed files with 22 additions and 13 deletions

View File

@ -2,6 +2,7 @@ use crate::{
commands::{
Command, RequestParserError, RequestParserResult, ResponseAttributes, ResponseParserError,
},
filter::parse_filter,
Request,
};
@ -12,8 +13,7 @@ impl Command for PlaylistFind {
const COMMAND: &'static str = "playlistfind";
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
let filter = parts.next().ok_or(RequestParserError::UnexpectedEOF)?;
let filter = filter.to_string();
let filter = parse_filter(&mut parts)?;
let mut sort_or_window = parts.next();
let mut sort = None;

View File

@ -2,6 +2,7 @@ use crate::{
commands::{
Command, RequestParserError, RequestParserResult, ResponseAttributes, ResponseParserError,
},
filter::parse_filter,
Request,
};
@ -12,10 +13,7 @@ impl Command for PlaylistSearch {
const COMMAND: &'static str = "playlistsearch";
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
let filter = parts.next().ok_or(RequestParserError::UnexpectedEOF)?;
let filter = filter
.parse()
.map_err(|_| RequestParserError::SyntaxError(0, filter.to_string()))?;
let filter = parse_filter(&mut parts)?;
let mut sort_or_window = parts.next();
let mut sort = None;

View File

@ -3,7 +3,8 @@ use crate::{
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
ResponseParserError,
},
common::{Filter, PlaylistName},
common::PlaylistName,
filter::parse_filter,
};
pub struct SearchPlaylist;
@ -18,10 +19,7 @@ impl Command for SearchPlaylist {
.parse::<PlaylistName>()
.map_err(|_| RequestParserError::SyntaxError(0, name.to_owned()))?;
let filter = parts.next().ok_or(RequestParserError::UnexpectedEOF)?;
let filter = filter
.parse::<Filter>()
.map_err(|_| RequestParserError::SyntaxError(0, filter.to_owned()))?;
let filter = parse_filter(&mut parts)?;
let range = parts
.next()

View File

@ -95,7 +95,6 @@ pub type TagName = String;
pub type TagValue = String;
pub type Uri = String;
pub type Path = String;
pub type Filter = String;
pub type Sort = String;
pub type Version = String;
pub type Feature = String;

View File

@ -1,11 +1,20 @@
use crate::common::{Priority, Tag};
use std::str::SplitWhitespace;
use serde::{Deserialize, Serialize};
use crate::{
commands::RequestParserError,
common::{Priority, Tag},
};
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum CaseSensitivity {
CaseSensitive,
CaseInsensitive,
CommandDependent,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum Filter {
Not(Box<Filter>),
And(Box<Filter>, Box<Filter>),
@ -30,3 +39,7 @@ pub enum Filter {
},
PrioCmp(Priority),
}
pub fn parse_filter(parts: &mut SplitWhitespace<'_>) -> Result<Filter, RequestParserError> {
todo!()
}

View File

@ -5,6 +5,7 @@ use serde::{Deserialize, Serialize};
use crate::common::*;
use crate::commands::*;
use crate::filter::Filter;
// TODO: SingleLineString