feat: get apps by tag

OS-26
This commit is contained in:
Artemy 2022-07-28 15:41:59 +03:00
parent faad9ea93a
commit 11628b0190
4 changed files with 21 additions and 1 deletions

View file

@ -159,6 +159,11 @@ impl Core {
.await .await
} }
pub async fn get_apps_by_tag(&self, info: &AppTags) -> Vec<Document> {
self.get_collection_with_params(&self.apps, doc! {"tags":{"$in":&info.tags}})
.await
}
pub async fn get_versions(&self, app_id: &String) -> Vec<Document> { pub async fn get_versions(&self, app_id: &String) -> Vec<Document> {
self.get_collection_with_params_and_sort( self.get_collection_with_params_and_sort(
&self.apps_versions, &self.apps_versions,

View file

@ -93,7 +93,8 @@ async fn main() -> std::io::Result<()> {
.service(routes::change_password) .service(routes::change_password)
.service(routes::write_review) .service(routes::write_review)
.service(routes::add_app_to_personal_library) .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( .service(
web::scope("/auth") web::scope("/auth")

View file

@ -21,6 +21,15 @@ 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)
} }
#[post("/apps_by_tag")]
#[has_any_permission("user", "admin")]
pub async fn apps_by_tags(
app_data: web::Data<crate::AppState>,
info: web::Json<AppTags>,
) -> impl Responder {
HttpResponse::Ok().json(app_data.core.get_apps_by_tag(&info).await)
}
#[get("/reviews/{app_id}")] #[get("/reviews/{app_id}")]
#[has_any_permission("user", "admin")] #[has_any_permission("user", "admin")]
pub async fn reviews( pub async fn reviews(

View file

@ -52,3 +52,8 @@ pub struct PasswordsInf {
pub struct AppInfo { pub struct AppInfo {
pub app_id: String, pub app_id: String,
} }
#[derive(Debug, Serialize, Deserialize)]
pub struct AppTags {
pub tags: Vec<String>,
}