refactor: change app_name_id to app_id

This commit is contained in:
Artemy 2022-07-28 12:23:10 +03:00
parent cbae3f458e
commit ba25d9a398
3 changed files with 17 additions and 17 deletions

View file

@ -38,7 +38,7 @@ impl Core {
} }
pub async fn get_app(&self, name: &String) -> serde_json::Value { 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 { match response {
Ok(response) => match response { Ok(response) => match response {
Some(result) => json!({ 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 let result = self
.reviews .reviews
.aggregate( .aggregate(
[ [
doc! {"$match":{"app_name_id":app_name_id}}, doc! {"$match":{"app_id":app_id}},
doc! { doc! {
"$group": { "$group": {
"_id": "$app_name_id", "_id": "$app_id",
"rating": { "rating": {
"$avg": "$score" "$avg": "$score"
}, },
@ -136,7 +136,7 @@ impl Core {
.build(); .build();
let response = self let response = self
.apps .apps
.find_one(doc! {"name_id":&info.app_name_id}, options) .find_one(doc! {"app_id":&info.app_id}, options)
.await; .await;
match response { match response {
@ -148,7 +148,7 @@ impl Core {
.update_one( .update_one(
doc! {"user_name": name}, doc! {"user_name": name},
doc! {"$set": { doc! {"$set": {
"app_name_id":&info.app_name_id, "app_id":&info.app_id,
"text":&info.text, "text":&info.text,
"score":&info.score, "score":&info.score,
"timestamp":Utc::now().timestamp() "timestamp":Utc::now().timestamp()
@ -254,7 +254,7 @@ impl Core {
let options = FindOneOptions::builder() let options = FindOneOptions::builder()
.projection(doc! {"_id" : 1}) .projection(doc! {"_id" : 1})
.build(); .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 { match response {
Ok(response) => match response { Ok(response) => match response {
Some(_) => { Some(_) => {

View file

@ -21,22 +21,22 @@ pub async fn apps(app_data: web::Data<crate::AppState>) -> impl Responder {
HttpResponse::Ok().json(app_data.core.get_apps().await) HttpResponse::Ok().json(app_data.core.get_apps().await)
} }
#[get("/reviews/{app_name_id}")] #[get("/reviews/{app_id}")]
#[has_any_permission("user", "admin")] #[has_any_permission("user", "admin")]
pub async fn reviews( pub async fn reviews(
app_data: web::Data<crate::AppState>, app_data: web::Data<crate::AppState>,
app_name_id: web::Path<String>, app_id: web::Path<String>,
) -> impl Responder { ) -> 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")] #[has_any_permission("user", "admin")]
pub async fn rating( pub async fn rating(
app_data: web::Data<crate::AppState>, app_data: web::Data<crate::AppState>,
app_name_id: web::Path<String>, app_id: web::Path<String>,
) -> impl Responder { ) -> impl Responder {
response(app_data.core.get_rating(&app_name_id).await) response(app_data.core.get_rating(&app_id).await)
} }
#[get("/app/{name}")] #[get("/app/{name}")]
@ -85,7 +85,7 @@ pub async fn add_app_to_personal_library(
response( response(
app_data app_data
.core .core
.add_app_to_personal_library(&username(req), &app_info.name) .add_app_to_personal_library(&username(req), &app_info.app_id)
.await, .await,
) )
} }
@ -100,7 +100,7 @@ pub async fn delete_app_from_personal_library(
response( response(
app_data app_data
.core .core
.delete_app_from_personal_library(&username(req), &app_info.name) .delete_app_from_personal_library(&username(req), &app_info.app_id)
.await, .await,
) )
} }

View file

@ -37,7 +37,7 @@ pub struct UserData {
#[derive(Debug, Serialize, Deserialize)] #[derive(Debug, Serialize, Deserialize)]
pub struct ReviewData { pub struct ReviewData {
pub app_name_id: String, pub app_id: String,
pub score: i32, pub score: i32,
pub text: String, pub text: String,
} }
@ -50,5 +50,5 @@ pub struct PasswordsInf {
#[derive(Debug, Serialize, Deserialize)] #[derive(Debug, Serialize, Deserialize)]
pub struct AppInfo { pub struct AppInfo {
pub name: String, pub app_id: String,
} }