11use actix_web:: { web, HttpResponse , Responder } ;
22use bson:: { doc, Bson } ;
3+ use chrono:: prelude:: * ;
34use futures:: stream:: StreamExt ;
45use mongodb:: { options:: FindOptions , Client } ;
5- use std:: sync:: Mutex ;
6- use chrono:: prelude:: * ;
76use serde:: Deserialize ;
8- use std:: env ;
7+ use std:: sync :: Mutex ;
98
109#[ derive( Deserialize ) ]
1110pub struct UserData {
@@ -15,8 +14,8 @@ pub struct UserData {
1514#[ derive( Deserialize ) ]
1615pub struct NewDataPool {
1716 pub id : String ,
18- pub poolName : String , //User defined pool name
19- pub sealedData : String , //Update data format to match sealed data
17+ pub pool_name : String , //User defined pool name
18+ pub sealed_data : String , //Update data format to match sealed data
2019}
2120
2221// Mongo DB (CosmosDB) Name
@@ -33,15 +32,18 @@ pub fn scoped_config(cfg: &mut web::ServiceConfig) {
3332}
3433
3534// This function accepts application data
36- async fn get_data ( data : web:: Data < Mutex < Client > > , existingUser : web:: Json < UserData > ) -> impl Responder {
35+ async fn get_data (
36+ data : web:: Data < Mutex < Client > > ,
37+ existing_user : web:: Json < UserData > ,
38+ ) -> impl Responder {
3739 let data_collection = data
3840 . lock ( )
3941 . unwrap ( )
4042 . database ( MONGO_DB )
4143 . collection ( MONGO_COLLECTION ) ;
4244
43- let userId = & existingUser . id ;
44- let filter = doc ! { "userId " : userId } ;
45+ let user_id = & existing_user . id ;
46+ let filter = doc ! { "user_id " : user_id } ;
4547 let find_options = FindOptions :: builder ( ) . sort ( doc ! { "_id" : -1 } ) . build ( ) ;
4648 let mut cursor = data_collection. find ( filter, find_options) . await . unwrap ( ) ;
4749
@@ -59,14 +61,17 @@ async fn get_data(data: web::Data<Mutex<Client>>, existingUser: web::Json<UserDa
5961 HttpResponse :: Ok ( ) . json ( results)
6062}
6163
62- async fn add_data ( data : web:: Data < Mutex < Client > > , new_pool : web:: Json < NewDataPool > ) -> impl Responder {
64+ async fn add_data (
65+ data : web:: Data < Mutex < Client > > ,
66+ new_pool : web:: Json < NewDataPool > ,
67+ ) -> impl Responder {
6368 let data_collection = data
6469 . lock ( )
6570 . unwrap ( )
6671 . database ( MONGO_DB )
6772 . collection ( MONGO_COLLECTION ) ;
6873
69- match data_collection. insert_one ( doc ! { "userId " : & new_pool. id, "poolName " : & new_pool. poolName , "sealedData " : & new_pool. sealedData , "createdOn " : Bson :: DateTime ( Utc :: now( ) ) } , None ) . await {
74+ match data_collection. insert_one ( doc ! { "user_id " : & new_pool. id, "pool_name " : & new_pool. pool_name , "sealed_data " : & new_pool. sealed_data , "created_on " : Bson :: DateTime ( Utc :: now( ) ) } , None ) . await {
7075 Ok ( db_result) => {
7176 if let Some ( new_id) = db_result. inserted_id . as_object_id ( ) {
7277 println ! ( "New document inserted with id {}" , new_id) ;
0 commit comments