From 11628b019029a4e1a1f205dbaa70793ac083f9ac Mon Sep 17 00:00:00 2001 From: Artemy Date: Thu, 28 Jul 2022 15:41:59 +0300 Subject: [PATCH] feat: get apps by tag OS-26 --- src/core.rs | 5 +++++ src/main.rs | 3 ++- src/routes.rs | 9 +++++++++ src/types.rs | 5 +++++ 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/core.rs b/src/core.rs index 7949bcb..9abcb4a 100644 --- a/src/core.rs +++ b/src/core.rs @@ -159,6 +159,11 @@ impl Core { .await } + pub async fn get_apps_by_tag(&self, info: &AppTags) -> Vec { + self.get_collection_with_params(&self.apps, doc! {"tags":{"$in":&info.tags}}) + .await + } + pub async fn get_versions(&self, app_id: &String) -> Vec { self.get_collection_with_params_and_sort( &self.apps_versions, diff --git a/src/main.rs b/src/main.rs index bbaf605..cfe28b1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -93,7 +93,8 @@ async fn main() -> std::io::Result<()> { .service(routes::change_password) .service(routes::write_review) .service(routes::add_app_to_personal_library) - .service(routes::delete_app_from_personal_library), + .service(routes::delete_app_from_personal_library) + .service(routes::apps_by_tags), ) .service( web::scope("/auth") diff --git a/src/routes.rs b/src/routes.rs index 30bb4aa..6df8d30 100644 --- a/src/routes.rs +++ b/src/routes.rs @@ -21,6 +21,15 @@ pub async fn apps(app_data: web::Data) -> impl Responder { HttpResponse::Ok().json(app_data.core.get_apps().await) } +#[post("/apps_by_tag")] +#[has_any_permission("user", "admin")] +pub async fn apps_by_tags( + app_data: web::Data, + info: web::Json, +) -> impl Responder { + HttpResponse::Ok().json(app_data.core.get_apps_by_tag(&info).await) +} + #[get("/reviews/{app_id}")] #[has_any_permission("user", "admin")] pub async fn reviews( diff --git a/src/types.rs b/src/types.rs index 170c997..27d9fd7 100644 --- a/src/types.rs +++ b/src/types.rs @@ -52,3 +52,8 @@ pub struct PasswordsInf { pub struct AppInfo { pub app_id: String, } + +#[derive(Debug, Serialize, Deserialize)] +pub struct AppTags { + pub tags: Vec, +}