mirror of
https://github.com/OSMA-D/osma-server.git
synced 2024-11-24 05:46:23 +03:00
feat: get latest version
OS-29
This commit is contained in:
parent
32be9b54a4
commit
faad9ea93a
3 changed files with 53 additions and 1 deletions
42
src/core.rs
42
src/core.rs
|
@ -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(
|
pub async fn delete_app_from_personal_library(
|
||||||
&self,
|
&self,
|
||||||
name: &String,
|
name: &String,
|
||||||
|
|
|
@ -87,6 +87,7 @@ async fn main() -> std::io::Result<()> {
|
||||||
.service(routes::rating)
|
.service(routes::rating)
|
||||||
.service(routes::versions)
|
.service(routes::versions)
|
||||||
.service(routes::personal_library)
|
.service(routes::personal_library)
|
||||||
|
.service(routes::latest_version)
|
||||||
//post
|
//post
|
||||||
.service(routes::update)
|
.service(routes::update)
|
||||||
.service(routes::change_password)
|
.service(routes::change_password)
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use crate::types::*;
|
use crate::types::*;
|
||||||
use actix_web::{get, post, web, HttpRequest, HttpResponse, Responder};
|
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")]
|
#[post("/signup")]
|
||||||
pub async fn signup(app_data: web::Data<crate::AppState>, user: web::Json<User>) -> impl Responder {
|
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)
|
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")]
|
#[get("/personal_library")]
|
||||||
#[has_any_permission("user", "admin")]
|
#[has_any_permission("user", "admin")]
|
||||||
pub async fn personal_library(
|
pub async fn personal_library(
|
||||||
|
|
Loading…
Add table
Reference in a new issue