Skip to content

Commit d4aceb8

Browse files
committed
feat: Add filter functionality
1 parent 454e6b0 commit d4aceb8

File tree

1 file changed

+9
-4
lines changed
  • rust-workspace/projects/data-server/src/data_handlers

1 file changed

+9
-4
lines changed

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ use chrono::prelude::*;
77
use serde::Deserialize;
88
use std::env;
99

10+
#[derive(Deserialize)]
11+
pub struct UserData {
12+
pub id: String,
13+
}
14+
1015
#[derive(Deserialize)]
1116
pub struct NewDataPool {
1217
pub id: String,
@@ -28,15 +33,15 @@ pub fn scoped_config(cfg: &mut web::ServiceConfig) {
2833
}
2934

3035
// This function accepts application data
31-
async fn get_data(data: web::Data<Mutex<Client>>) -> impl Responder {
36+
async fn get_data(data: web::Data<Mutex<Client>>, existingUser: web::Json<UserData>) -> impl Responder {
3237
let data_collection = data
3338
.lock()
3439
.unwrap()
3540
.database(MONGO_DB)
3641
.collection(MONGO_COLLECTION);
3742

38-
let filter = doc! { };
39-
// Tweak find options to find specific user's data
43+
let userId = &existingUser.id;
44+
let filter = doc! {"userId": userId};
4045
let find_options = FindOptions::builder().sort(doc! { "_id": -1}).build();
4146
let mut cursor = data_collection.find(filter, find_options).await.unwrap();
4247

@@ -74,4 +79,4 @@ async fn add_data(data: web::Data<Mutex<Client>>, new_pool: web::Json<NewDataPoo
7479
return HttpResponse::InternalServerError().finish()
7580
}
7681
}
77-
}
82+
}

0 commit comments

Comments
 (0)