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 {
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(_) => {

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)
}
#[get("/reviews/{app_name_id}")]
#[get("/reviews/{app_id}")]
#[has_any_permission("user", "admin")]
pub async fn reviews(
app_data: web::Data<crate::AppState>,
app_name_id: web::Path<String>,
app_id: web::Path<String>,
) -> 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<crate::AppState>,
app_name_id: web::Path<String>,
app_id: web::Path<String>,
) -> 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,
)
}

View file

@ -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,
}