From ba25d9a39800658b1e3be628fe93645f4686b948 Mon Sep 17 00:00:00 2001 From: Artemy Date: Thu, 28 Jul 2022 12:23:10 +0300 Subject: [PATCH] refactor: change app_name_id to app_id --- src/core.rs | 14 +++++++------- src/routes.rs | 16 ++++++++-------- src/types.rs | 4 ++-- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/core.rs b/src/core.rs index aa27cb2..24fef40 100644 --- a/src/core.rs +++ b/src/core.rs @@ -38,7 +38,7 @@ impl Core { } pub async fn get_app(&self, name: &String) -> serde_json::Value { - let response = self.apps.find_one(doc! {"name_id":&name}, None).await; + let response = self.apps.find_one(doc! {"app_id":&name}, None).await; match response { Ok(response) => match response { Some(result) => json!({ @@ -61,15 +61,15 @@ impl Core { } } - pub async fn get_rating(&self, app_name_id: &String) -> serde_json::Value { + pub async fn get_rating(&self, app_id: &String) -> serde_json::Value { let result = self .reviews .aggregate( [ - doc! {"$match":{"app_name_id":app_name_id}}, + doc! {"$match":{"app_id":app_id}}, doc! { "$group": { - "_id": "$app_name_id", + "_id": "$app_id", "rating": { "$avg": "$score" }, @@ -136,7 +136,7 @@ impl Core { .build(); let response = self .apps - .find_one(doc! {"name_id":&info.app_name_id}, options) + .find_one(doc! {"app_id":&info.app_id}, options) .await; match response { @@ -148,7 +148,7 @@ impl Core { .update_one( doc! {"user_name": name}, doc! {"$set": { - "app_name_id":&info.app_name_id, + "app_id":&info.app_id, "text":&info.text, "score":&info.score, "timestamp":Utc::now().timestamp() @@ -254,7 +254,7 @@ impl Core { let options = FindOneOptions::builder() .projection(doc! {"_id" : 1}) .build(); - let response = self.apps.find_one(doc! {"name_id":&app}, options).await; + let response = self.apps.find_one(doc! {"app_id":&app}, options).await; match response { Ok(response) => match response { Some(_) => { diff --git a/src/routes.rs b/src/routes.rs index 7841b67..e18f81a 100644 --- a/src/routes.rs +++ b/src/routes.rs @@ -21,22 +21,22 @@ pub async fn apps(app_data: web::Data) -> impl Responder { HttpResponse::Ok().json(app_data.core.get_apps().await) } -#[get("/reviews/{app_name_id}")] +#[get("/reviews/{app_id}")] #[has_any_permission("user", "admin")] pub async fn reviews( app_data: web::Data, - app_name_id: web::Path, + app_id: web::Path, ) -> impl Responder { - HttpResponse::Ok().json(app_data.core.get_reviews(&app_name_id).await) + HttpResponse::Ok().json(app_data.core.get_reviews(&app_id).await) } -#[get("/rating/{app_name_id}")] +#[get("/rating/{app_id}")] #[has_any_permission("user", "admin")] pub async fn rating( app_data: web::Data, - app_name_id: web::Path, + app_id: web::Path, ) -> impl Responder { - response(app_data.core.get_rating(&app_name_id).await) + response(app_data.core.get_rating(&app_id).await) } #[get("/app/{name}")] @@ -85,7 +85,7 @@ pub async fn add_app_to_personal_library( response( app_data .core - .add_app_to_personal_library(&username(req), &app_info.name) + .add_app_to_personal_library(&username(req), &app_info.app_id) .await, ) } @@ -100,7 +100,7 @@ pub async fn delete_app_from_personal_library( response( app_data .core - .delete_app_from_personal_library(&username(req), &app_info.name) + .delete_app_from_personal_library(&username(req), &app_info.app_id) .await, ) } diff --git a/src/types.rs b/src/types.rs index 0716bf0..170c997 100644 --- a/src/types.rs +++ b/src/types.rs @@ -37,7 +37,7 @@ pub struct UserData { #[derive(Debug, Serialize, Deserialize)] pub struct ReviewData { - pub app_name_id: String, + pub app_id: String, pub score: i32, pub text: String, } @@ -50,5 +50,5 @@ pub struct PasswordsInf { #[derive(Debug, Serialize, Deserialize)] pub struct AppInfo { - pub name: String, + pub app_id: String, }