11use axum:: {
2- extract:: Path ,
2+ extract:: { Path , Query } ,
33 http:: StatusCode ,
44 middleware,
55 response:: IntoResponse ,
@@ -10,16 +10,14 @@ use rust_db_manager_core::{
1010 commons:: {
1111 configuration:: configuration:: Configuration , utils:: document_keys_to_filter_element,
1212 } ,
13- domain:: filter:: data_base_query :: DataBaseQuery ,
13+ domain:: filter:: { collection_query :: CollectionQuery , document_query :: DocumentQuery } ,
1414} ;
1515
1616use crate :: commons:: exception:: api_exception:: ApiException ;
1717
1818use super :: {
1919 dto:: {
20- document:: { dto_document_data:: DTODocumentData , dto_document_key:: DTODocumentKey } ,
21- dto_create_document:: DTOCreateDocument ,
22- dto_update_document:: DTOUpdateDocument ,
20+ collection:: dto_collection_data:: DTOCollectionData , document:: { dto_document_data:: DTODocumentData , dto_document_key:: DTODocumentKey } , dto_create_document:: DTOCreateDocument , dto_update_document:: DTOUpdateDocument , pagination:: dto_query_pagination:: DTOQueryPagination
2321 } ,
2422 handler, utils,
2523} ;
@@ -61,7 +59,7 @@ impl ControllerDocument {
6159 }
6260
6361 let filter = document_keys_to_filter_element ( keys) ;
64- let query = DataBaseQuery :: from_filter ( data_base, collection, filter) ;
62+ let query = DocumentQuery :: from_filter ( data_base, collection, filter) ;
6563
6664 let r_document = result. unwrap ( ) . find ( & query) . await ;
6765 if let Err ( error) = r_document {
@@ -79,7 +77,7 @@ impl ControllerDocument {
7977 Ok ( Json ( DTODocumentData :: from ( & document. unwrap ( ) ) ) )
8078 }
8179
82- async fn find_all ( Path ( ( service, data_base, collection) ) : Path < ( String , String , String ) > ) -> Result < Json < Vec < DTODocumentData > > , impl IntoResponse > {
80+ async fn find_all ( Path ( ( service, data_base, collection) ) : Path < ( String , String , String ) > , Query ( params ) : Query < DTOQueryPagination > ) -> Result < Json < DTOCollectionData > , impl IntoResponse > {
8381 let o_db_service = Configuration :: find_service ( & service) ;
8482 if o_db_service. is_none ( ) {
8583 return Err ( utils:: not_found ( ) ) ;
@@ -91,18 +89,15 @@ impl ControllerDocument {
9189 return Err ( exception. into_response ( ) ) ;
9290 }
9391
94- let query = DataBaseQuery :: from ( data_base, collection) ;
92+ let query = DocumentQuery :: from ( data_base, collection, Some ( params . limit ) , Some ( params . offset ) , None ) ;
9593
96- let documents = result. unwrap ( ) . find_all ( & query) . await ;
97- if let Err ( error) = documents {
94+ let data = result. unwrap ( ) . find_all ( & query) . await ;
95+ if let Err ( error) = data {
9896 let exception = ApiException :: from ( StatusCode :: INTERNAL_SERVER_ERROR . as_u16 ( ) , error) ;
9997 return Err ( exception. into_response ( ) ) ;
10098 }
10199
102- Ok ( Json ( documents. unwrap ( ) . iter ( )
103- . map ( |d| DTODocumentData :: from ( d) )
104- . collect ( ) )
105- )
100+ Ok ( Json ( DTOCollectionData :: from ( & data. unwrap ( ) ) ) )
106101 }
107102
108103 async fn insert ( Path ( ( service, data_base, collection) ) : Path < ( String , String , String ) > , Json ( dto) : Json < DTOCreateDocument > ) -> Result < Json < DTODocumentData > , impl IntoResponse > {
@@ -117,7 +112,7 @@ impl ControllerDocument {
117112 return Err ( exception. into_response ( ) ) ;
118113 }
119114
120- let query = DataBaseQuery :: from ( data_base, collection) ;
115+ let query = CollectionQuery :: from ( data_base, collection) ;
121116
122117 let document = result. unwrap ( ) . insert ( & query, & dto. document ) . await ;
123118 if let Err ( error) = document {
@@ -150,7 +145,7 @@ impl ControllerDocument {
150145 }
151146
152147 let filter = document_keys_to_filter_element ( keys) ;
153- let query = DataBaseQuery :: from_filter ( data_base, collection, filter) ;
148+ let query = DocumentQuery :: from_filter ( data_base, collection, filter) ;
154149
155150 let documents = result. unwrap ( ) . update ( & query, & dto. document ) . await ;
156151 if let Err ( error) = documents {
@@ -186,7 +181,7 @@ impl ControllerDocument {
186181 }
187182
188183 let filter = document_keys_to_filter_element ( keys) ;
189- let query = DataBaseQuery :: from_filter ( data_base, collection, filter) ;
184+ let query = DocumentQuery :: from_filter ( data_base, collection, filter) ;
190185
191186 let documents = result. unwrap ( ) . delete ( & query) . await ;
192187 if let Err ( error) = documents {
0 commit comments