Skip to content

Commit d2b142f

Browse files
author
Rafael Ruiz
committed
[FEATURE] Pagination logic implemented.
1 parent 4b3ad6d commit d2b142f

File tree

8 files changed

+211
-155
lines changed

8 files changed

+211
-155
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
use crate::domain::document::document_data::DocumentData;
2+
3+
pub struct CollectionData {
4+
total: usize,
5+
limit: Option<usize>,
6+
offset: Option<usize>,
7+
documents: Vec<DocumentData>
8+
}
9+
10+
impl CollectionData {
11+
12+
pub fn new(total: usize, limit: Option<usize>, offset: Option<usize>, documents: Vec<DocumentData>) -> Self {
13+
Self {
14+
total, limit, offset, documents
15+
}
16+
}
17+
18+
pub fn total(&self) -> usize {
19+
self.total
20+
}
21+
22+
pub fn limit(&self) -> Option<usize> {
23+
self.limit
24+
}
25+
26+
pub fn offset(&self) -> Option<usize> {
27+
self.offset
28+
}
29+
30+
pub fn documents(&self) -> Vec<DocumentData> {
31+
self.documents.clone()
32+
}
33+
34+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#[derive(Clone)]
2+
pub struct CollectionQuery {
3+
data_base: String,
4+
collection: String
5+
}
6+
7+
impl CollectionQuery {
8+
9+
pub fn from(data_base: String, collection: String) -> Self {
10+
Self {
11+
data_base, collection
12+
}
13+
}
14+
15+
pub fn data_base(&self) -> String {
16+
return self.data_base.clone();
17+
}
18+
19+
pub fn collection(&self) -> String {
20+
return self.collection.clone();
21+
}
22+
23+
}
Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,18 @@
1-
use super::filter_element::FilterElement;
2-
31
#[derive(Clone)]
42
pub struct DataBaseQuery {
53
data_base: String,
6-
collection: String,
7-
filter: Option<FilterElement>
84
}
95

106
impl DataBaseQuery {
117

12-
pub fn from(data_base: String, collection: String) -> DataBaseQuery {
13-
DataBaseQuery {
14-
data_base: data_base,
15-
collection: collection,
16-
filter: None
17-
}
18-
}
19-
20-
pub fn from_data_base(data_base: String) -> DataBaseQuery {
21-
DataBaseQuery {
22-
data_base: data_base,
23-
collection: String::new(),
24-
filter: None
25-
}
26-
}
27-
28-
pub fn from_filter(data_base: String, collection: String, filter: FilterElement) -> DataBaseQuery {
29-
DataBaseQuery {
30-
data_base: data_base,
31-
collection: collection,
32-
filter: Some(filter)
8+
pub fn from(data_base: String) -> Self {
9+
Self {
10+
data_base
3311
}
3412
}
3513

3614
pub fn data_base(&self) -> String {
3715
return self.data_base.clone();
3816
}
3917

40-
pub fn collection(&self) -> String {
41-
return self.collection.clone();
42-
}
43-
44-
pub fn filter(&self) -> Option<FilterElement> {
45-
return self.filter.clone();
46-
}
47-
4818
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
use super::filter_element::FilterElement;
2+
3+
#[derive(Clone)]
4+
pub struct DocumentQuery {
5+
data_base: String,
6+
collection: String,
7+
skip: Option<usize>,
8+
limit: Option<usize>,
9+
filter: Option<FilterElement>
10+
}
11+
12+
impl DocumentQuery {
13+
14+
pub fn from_filter(data_base: String, collection: String, filter: FilterElement) -> Self {
15+
Self::from(data_base, collection, None, None, Some(filter))
16+
}
17+
18+
pub fn from(data_base: String, collection: String, skip: Option<usize>, limit: Option<usize>, filter: Option<FilterElement>) -> Self {
19+
Self {
20+
data_base: data_base,
21+
collection: collection,
22+
limit: limit,
23+
skip: skip,
24+
filter: filter
25+
}
26+
}
27+
28+
pub fn data_base(&self) -> String {
29+
return self.data_base.clone();
30+
}
31+
32+
pub fn collection(&self) -> String {
33+
return self.collection.clone();
34+
}
35+
36+
pub fn skip(&self) -> Option<usize> {
37+
return self.skip;
38+
}
39+
40+
pub fn limit(&self) -> Option<usize> {
41+
return self.limit;
42+
}
43+
44+
pub fn filter(&self) -> Option<FilterElement> {
45+
return self.filter.clone();
46+
}
47+
48+
}

src/infrastructure/repository/i_db_repository.rs

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@ use crate::{
44
commons::exception::connect_exception::ConnectException,
55
domain::{
66
collection::{
7-
collection_definition::CollectionDefinition,
8-
generate_collection_query::GenerateCollectionQuery,
7+
collection_data::CollectionData, collection_definition::CollectionDefinition, generate_collection_query::GenerateCollectionQuery
98
},
109
data_base::generate_database_query::GenerateDatabaseQuery,
1110
document::{document_data::DocumentData, document_schema::DocumentSchema},
12-
filter::data_base_query::DataBaseQuery,
11+
filter::{collection_query::CollectionQuery, data_base_query::DataBaseQuery, document_query::DocumentQuery},
1312
table::table_data_group::TableDataGroup,
1413
},
1514
};
@@ -26,23 +25,20 @@ pub trait IDBRepository: Clone + Send + Sync {
2625
async fn data_base_drop(&self, query: &GenerateDatabaseQuery) -> Result<String, ConnectException>;
2726

2827
async fn collection_accept_schema(&self) -> Result<CollectionDefinition, ConnectException>;
29-
async fn collection_metadata(&self, query: &DataBaseQuery) -> Result<Vec<TableDataGroup>, ConnectException>;
28+
async fn collection_metadata(&self, query: &CollectionQuery) -> Result<Vec<TableDataGroup>, ConnectException>;
3029
async fn collection_find_all(&self, query: &DataBaseQuery) -> Result<Vec<String>, ConnectException>;
31-
async fn collection_exists(&self, query: &DataBaseQuery) -> Result<bool, ConnectException>;
30+
async fn collection_exists(&self, query: &CollectionQuery) -> Result<bool, ConnectException>;
3231
async fn collection_create(&self, query: &GenerateCollectionQuery) -> Result<String, ConnectException>;
3332
async fn collection_drop(&self, query: &GenerateCollectionQuery) -> Result<String, ConnectException>;
34-
async fn collection_rename(&self, query: &DataBaseQuery, name: &str) -> Result<String, ConnectException>;
35-
async fn collection_export(&self, query: &DataBaseQuery) -> Result<Vec<DocumentData>, ConnectException>;
36-
async fn collection_import(&self, query: &DataBaseQuery, documents: Vec<String>) -> Result<String, ConnectException>;
37-
38-
async fn find_query_lite(&self, query: &DataBaseQuery) -> Result<Vec<String>, ConnectException>;
39-
async fn find_query(&self, query: &DataBaseQuery) -> Result<Vec<DocumentData>, ConnectException>;
40-
41-
async fn find_all_lite(&self, query: &DataBaseQuery) -> Result<Vec<String>, ConnectException>;
42-
async fn find_all(&self, query: &DataBaseQuery) -> Result<Vec<DocumentData>, ConnectException>;
43-
async fn find(&self, query: &DataBaseQuery) -> Result<Option<DocumentData>, ConnectException>;
44-
async fn schema(&self, query: &DataBaseQuery) -> Result<DocumentSchema, ConnectException>;
45-
async fn insert(&self, query: &DataBaseQuery, value: &str) -> Result<DocumentData, ConnectException>;
46-
async fn update(&self, query: &DataBaseQuery, value: &str) -> Result<Vec<DocumentData>, ConnectException>;
47-
async fn delete(&self, query: &DataBaseQuery) -> Result<Vec<DocumentData>, ConnectException>;
33+
async fn collection_rename(&self, query: &CollectionQuery, name: &str) -> Result<String, ConnectException>;
34+
async fn collection_export(&self, query: &CollectionQuery) -> Result<Vec<DocumentData>, ConnectException>;
35+
async fn collection_import(&self, query: &CollectionQuery, documents: Vec<String>) -> Result<String, ConnectException>;
36+
37+
async fn find_all(&self, query: &DocumentQuery) -> Result<CollectionData, ConnectException>;
38+
async fn find_query(&self, query: &DocumentQuery) -> Result<CollectionData, ConnectException>;
39+
async fn find(&self, query: &DocumentQuery) -> Result<Option<DocumentData>, ConnectException>;
40+
async fn schema(&self, query: &CollectionQuery) -> Result<DocumentSchema, ConnectException>;
41+
async fn insert(&self, query: &CollectionQuery, value: &str) -> Result<DocumentData, ConnectException>;
42+
async fn update(&self, query: &DocumentQuery, value: &str) -> Result<Vec<DocumentData>, ConnectException>;
43+
async fn delete(&self, query: &DocumentQuery) -> Result<Vec<DocumentData>, ConnectException>;
4844
}

0 commit comments

Comments
 (0)