Rename and change query filters
This commit is contained in:
parent
de37658b94
commit
ba7f268b99
3 changed files with 8 additions and 8 deletions
|
@ -116,12 +116,11 @@ impl<'a> BucketHelper<'a> {
|
||||||
.get_range(
|
.get_range(
|
||||||
&EmptyKey,
|
&EmptyKey,
|
||||||
None,
|
None,
|
||||||
Some(KeyFilter::Matches(pattern.to_string())),
|
Some(KeyFilter::MatchesAndNotDeleted(pattern.to_string())),
|
||||||
10,
|
10,
|
||||||
)
|
)
|
||||||
.await?
|
.await?
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.filter(|k| !k.state.is_deleted())
|
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
if candidates.len() != 1 {
|
if candidates.len() != 1 {
|
||||||
Err(Error::BadRequest(format!(
|
Err(Error::BadRequest(format!(
|
||||||
|
|
|
@ -152,7 +152,7 @@ pub struct KeyTable;
|
||||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||||
pub enum KeyFilter {
|
pub enum KeyFilter {
|
||||||
Deleted(DeletedFilter),
|
Deleted(DeletedFilter),
|
||||||
Matches(String),
|
MatchesAndNotDeleted(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TableSchema for KeyTable {
|
impl TableSchema for KeyTable {
|
||||||
|
@ -166,10 +166,11 @@ impl TableSchema for KeyTable {
|
||||||
fn matches_filter(entry: &Self::E, filter: &Self::Filter) -> bool {
|
fn matches_filter(entry: &Self::E, filter: &Self::Filter) -> bool {
|
||||||
match filter {
|
match filter {
|
||||||
KeyFilter::Deleted(df) => df.apply(entry.state.is_deleted()),
|
KeyFilter::Deleted(df) => df.apply(entry.state.is_deleted()),
|
||||||
KeyFilter::Matches(pat) => {
|
KeyFilter::MatchesAndNotDeleted(pat) => {
|
||||||
let pat = pat.to_lowercase();
|
let pat = pat.to_lowercase();
|
||||||
entry.key_id.to_lowercase().starts_with(&pat)
|
!entry.state.is_deleted()
|
||||||
|| entry.name.get().to_lowercase() == pat
|
&& (entry.key_id.to_lowercase().starts_with(&pat)
|
||||||
|
|| entry.name.get().to_lowercase() == pat)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@ impl PartitionKey for EmptyKey {
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, Serialize, Deserialize)]
|
#[derive(Clone, Copy, Debug, Serialize, Deserialize)]
|
||||||
pub enum DeletedFilter {
|
pub enum DeletedFilter {
|
||||||
All,
|
Any,
|
||||||
Deleted,
|
Deleted,
|
||||||
NotDeleted,
|
NotDeleted,
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,7 @@ pub enum DeletedFilter {
|
||||||
impl DeletedFilter {
|
impl DeletedFilter {
|
||||||
pub fn apply(&self, deleted: bool) -> bool {
|
pub fn apply(&self, deleted: bool) -> bool {
|
||||||
match self {
|
match self {
|
||||||
DeletedFilter::All => true,
|
DeletedFilter::Any => true,
|
||||||
DeletedFilter::Deleted => deleted,
|
DeletedFilter::Deleted => deleted,
|
||||||
DeletedFilter::NotDeleted => !deleted,
|
DeletedFilter::NotDeleted => !deleted,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue