feat: get latest version

OS-29
This commit is contained in:
Artemy 2022-07-28 15:14:10 +03:00
parent 32be9b54a4
commit faad9ea93a
3 changed files with 53 additions and 1 deletions

View file

@ -253,6 +253,48 @@ impl Core {
}
}
pub async fn get_latest_version(&self, app_id: &String) -> serde_json::Value {
let options = FindOptions::builder()
.projection(doc! {"_id" : 0})
.sort(doc! {"timestamp":-1})
.limit(1)
.build();
let result = self
.apps_versions
.find(doc! {"app_id":app_id}, options)
.await;
match result {
Ok(mut cursor) => match cursor.next().await {
Some(result) => match result {
Ok(result) => {
json! ({
"code":"ok_body",
"body":result
})
}
Err(_) => {
json! ({
"code":"err",
"msg":"Unknown error"
})
}
},
None => {
json! ({
"code":"denied",
"msg":"Versions of this app does not exists"
})
}
},
Err(_) => json! ({
"code":"denied",
"msg":"Unknown error"
}),
}
}
pub async fn delete_app_from_personal_library(
&self,
name: &String,

View file

@ -87,6 +87,7 @@ async fn main() -> std::io::Result<()> {
.service(routes::rating)
.service(routes::versions)
.service(routes::personal_library)
.service(routes::latest_version)
//post
.service(routes::update)
.service(routes::change_password)

View file

@ -1,6 +1,6 @@
use crate::types::*;
use actix_web::{get, post, web, HttpRequest, HttpResponse, Responder};
use actix_web_grants::proc_macro::{has_any_permission, has_permissions};
use actix_web_grants::proc_macro::has_any_permission;
#[post("/signup")]
pub async fn signup(app_data: web::Data<crate::AppState>, user: web::Json<User>) -> impl Responder {
@ -54,6 +54,15 @@ pub async fn app(app_data: web::Data<crate::AppState>, name: web::Path<String>)
response(app_data.core.get_app(&name).await)
}
#[get("/latest_version/{name}")]
#[has_any_permission("user", "admin")]
pub async fn latest_version(
app_data: web::Data<crate::AppState>,
name: web::Path<String>,
) -> impl Responder {
response(app_data.core.get_latest_version(&name).await)
}
#[get("/personal_library")]
#[has_any_permission("user", "admin")]
pub async fn personal_library(