Skip to content

Commit 7fa0869

Browse files
committed
refactor: remove unused imports + fix snake_case
1 parent 3d20c53 commit 7fa0869

File tree

3 files changed

+20
-15
lines changed

3 files changed

+20
-15
lines changed

rust-workspace/projects/data-server/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ edition = "2021"
77
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
88

99
[dependencies]
10-
mongodb = "1.0.0" #Change version for compatibility
10+
mongodb = "1.0.0" #Change version for compatibility
1111
bson = "1.0.0"
1212
serde = { version = "1.0", features = ["derive"] }
1313
actix-rt = "1.1.1"
1414
actix-web = "2.0"
1515
futures = "0.3.5"
16-
chrono = "0.4.11"
16+
chrono = "0.4.11"

rust-workspace/projects/data-server/src/data_handlers/mod.rs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
use actix_web::{web, HttpResponse, Responder};
22
use bson::{doc, Bson};
3+
use chrono::prelude::*;
34
use futures::stream::StreamExt;
45
use mongodb::{options::FindOptions, Client};
5-
use std::sync::Mutex;
6-
use chrono::prelude::*;
76
use serde::Deserialize;
8-
use std::env;
7+
use std::sync::Mutex;
98

109
#[derive(Deserialize)]
1110
pub struct UserData {
@@ -15,8 +14,8 @@ pub struct UserData {
1514
#[derive(Deserialize)]
1615
pub 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);

rust-workspace/projects/data-server/src/main.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use mongodb::{options::ClientOptions, Client};
21
use actix_web::{web, App, HttpServer};
2+
use mongodb::{options::ClientOptions, Client};
33
use std::env;
44
use std::sync::*;
55

@@ -11,7 +11,7 @@ async fn main() -> std::io::Result<()> {
1111
env::set_var("RUST_LOG", "actix_web=debug");
1212
// Remember to set connection string when starting the server
1313
let mongo_url = env::var("CONNECTION_STRING").unwrap();
14-
let mut client_options = ClientOptions::parse(&mongo_url).await.unwrap();
14+
let client_options = ClientOptions::parse(&mongo_url).await.unwrap();
1515
let client = web::Data::new(Mutex::new(Client::with_options(client_options).unwrap()));
1616
HttpServer::new(move || {
1717
App::new()
@@ -21,4 +21,4 @@ async fn main() -> std::io::Result<()> {
2121
.bind("127.0.0.1:8000")?
2222
.run()
2323
.await
24-
}
24+
}

0 commit comments

Comments
 (0)