1
1
use actix_web:: { web, HttpResponse , Responder } ;
2
2
use bson:: { doc, Bson } ;
3
+ use chrono:: prelude:: * ;
3
4
use futures:: stream:: StreamExt ;
4
5
use mongodb:: { options:: FindOptions , Client } ;
5
- use std:: sync:: Mutex ;
6
- use chrono:: prelude:: * ;
7
6
use serde:: Deserialize ;
8
- use std:: env ;
7
+ use std:: sync :: Mutex ;
9
8
10
9
#[ derive( Deserialize ) ]
11
10
pub struct UserData {
@@ -15,8 +14,8 @@ pub struct UserData {
15
14
#[ derive( Deserialize ) ]
16
15
pub struct NewDataPool {
17
16
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
20
19
}
21
20
22
21
// Mongo DB (CosmosDB) Name
@@ -33,15 +32,18 @@ pub fn scoped_config(cfg: &mut web::ServiceConfig) {
33
32
}
34
33
35
34
// 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 {
37
39
let data_collection = data
38
40
. lock ( )
39
41
. unwrap ( )
40
42
. database ( MONGO_DB )
41
43
. collection ( MONGO_COLLECTION ) ;
42
44
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 } ;
45
47
let find_options = FindOptions :: builder ( ) . sort ( doc ! { "_id" : -1 } ) . build ( ) ;
46
48
let mut cursor = data_collection. find ( filter, find_options) . await . unwrap ( ) ;
47
49
@@ -59,14 +61,17 @@ async fn get_data(data: web::Data<Mutex<Client>>, existingUser: web::Json<UserDa
59
61
HttpResponse :: Ok ( ) . json ( results)
60
62
}
61
63
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 {
63
68
let data_collection = data
64
69
. lock ( )
65
70
. unwrap ( )
66
71
. database ( MONGO_DB )
67
72
. collection ( MONGO_COLLECTION ) ;
68
73
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 {
70
75
Ok ( db_result) => {
71
76
if let Some ( new_id) = db_result. inserted_id . as_object_id ( ) {
72
77
println ! ( "New document inserted with id {}" , new_id) ;
0 commit comments