-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feat/1564-project-duration
- Loading branch information
Showing
29 changed files
with
827 additions
and
231 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
//! Document Reference filtering object. | ||
use crate::db::event::common::eq_or_ranged_uuid::EqOrRangedUuid; | ||
|
||
/// Document Reference filtering struct. | ||
#[derive(Clone, Debug)] | ||
pub(crate) struct DocumentRef { | ||
/// Document id filtering | ||
pub(crate) id: Option<EqOrRangedUuid>, | ||
/// Document ver filtering | ||
pub(crate) ver: Option<EqOrRangedUuid>, | ||
} | ||
|
||
impl DocumentRef { | ||
/// Return a sql conditional statement by the provided `table_field` | ||
pub(crate) fn conditional_stmt(&self, table_field: &str) -> String { | ||
let mut stmt = "TRUE".to_string(); | ||
if let Some(id) = &self.id { | ||
stmt.push_str(&format!( | ||
" AND {}", | ||
id.conditional_stmt(&format!("({table_field}->>'id')::uuid")) | ||
)); | ||
} | ||
if let Some(ver) = &self.ver { | ||
stmt.push_str(&format!( | ||
" AND {}", | ||
ver.conditional_stmt(&format!("({table_field}->>'ver')::uuid")) | ||
)); | ||
} | ||
stmt | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,13 @@ | ||
//! Signed docs queries | ||
mod doc_ref; | ||
mod full_signed_doc; | ||
mod query_filter; | ||
mod signed_doc_body; | ||
#[cfg(test)] | ||
mod tests; | ||
|
||
#[allow(unused_imports)] | ||
pub(crate) use doc_ref::DocumentRef; | ||
pub(crate) use full_signed_doc::{FullSignedDoc, SELECT_SIGNED_DOCS_TEMPLATE}; | ||
pub(crate) use query_filter::DocsQueryFilter; | ||
pub(crate) use signed_doc_body::{SignedDocBody, FILTERED_SELECT_SIGNED_DOCS_TEMPLATE}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
catalyst-gateway/bin/src/db/event/signed_docs/tests/filter_by_field.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
//! `filter_by_field` macro | ||
/// `filter_by_field` test case | ||
#[macro_export] | ||
macro_rules! filter_by_field { | ||
($doc:expr, $field:expr, $with_method:ident) => { | ||
#[allow(clippy::indexing_slicing)] | ||
if let Some(meta) = $doc.metadata() { | ||
let id = uuid::Uuid::from_str(meta[$field]["id"].clone().as_str().unwrap()).unwrap(); | ||
let ver = uuid::Uuid::from_str(meta[$field]["ver"].clone().as_str().unwrap()).unwrap(); | ||
|
||
// With id | ||
let filter = DocsQueryFilter::all().$with_method(DocumentRef { | ||
id: Some(EqOrRangedUuid::Eq(id)), | ||
ver: None, | ||
}); | ||
let mut res_docs = SignedDocBody::retrieve(&filter, &QueryLimits::ALL) | ||
.await | ||
.unwrap(); | ||
let res_doc = res_docs.try_next().await.unwrap().unwrap(); | ||
assert_eq!($doc.body(), &res_doc); | ||
|
||
// With ver | ||
let filter = DocsQueryFilter::all().$with_method(DocumentRef { | ||
id: None, | ||
ver: Some(EqOrRangedUuid::Eq(ver)), | ||
}); | ||
let mut res_docs = SignedDocBody::retrieve(&filter, &QueryLimits::ALL) | ||
.await | ||
.unwrap(); | ||
let res_doc = res_docs.try_next().await.unwrap().unwrap(); | ||
assert_eq!($doc.body(), &res_doc); | ||
|
||
// With both id and ver | ||
let filter = DocsQueryFilter::all().$with_method(DocumentRef { | ||
id: Some(EqOrRangedUuid::Eq(id)), | ||
ver: Some(EqOrRangedUuid::Eq(ver)), | ||
}); | ||
let mut res_docs = SignedDocBody::retrieve(&filter, &QueryLimits::ALL) | ||
.await | ||
.unwrap(); | ||
let res_doc = res_docs.try_next().await.unwrap().unwrap(); | ||
assert_eq!($doc.body(), &res_doc); | ||
} | ||
}; | ||
} | ||
|
||
pub(super) use filter_by_field; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.