feat: get personal library

OS-30
This commit is contained in:
Artemy 2022-07-28 14:18:59 +03:00
parent c0cb672750
commit 32be9b54a4
3 changed files with 39 additions and 0 deletions

View file

@ -63,6 +63,33 @@ impl Core {
} }
} }
pub async fn get_personal_library(&self, name: &String) -> serde_json::Value {
let response = self
.personal_libraries
.find_one(doc! {"name":&name}, None)
.await;
match response {
Ok(response) => match response {
Some(result) => json!({
"code":"ok_body",
"body": result.get_array("apps").unwrap()
}),
None => {
json! ({
"code":"denied",
"msg":"This user does not exist"
})
}
},
Err(_) => {
json! ({
"code":"err",
"msg":"Unknown error"
})
}
}
}
pub async fn get_rating(&self, app_id: &String) -> serde_json::Value { pub async fn get_rating(&self, app_id: &String) -> serde_json::Value {
let result = self let result = self
.reviews .reviews

View file

@ -80,11 +80,14 @@ async fn main() -> std::io::Result<()> {
.service( .service(
web::scope("/api") web::scope("/api")
.wrap(HttpAuthentication::bearer(jwt_validator)) .wrap(HttpAuthentication::bearer(jwt_validator))
//get
.service(routes::apps) .service(routes::apps)
.service(routes::app) .service(routes::app)
.service(routes::reviews) .service(routes::reviews)
.service(routes::rating) .service(routes::rating)
.service(routes::versions) .service(routes::versions)
.service(routes::personal_library)
//post
.service(routes::update) .service(routes::update)
.service(routes::change_password) .service(routes::change_password)
.service(routes::write_review) .service(routes::write_review)

View file

@ -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("/personal_library")]
#[has_any_permission("user", "admin")]
pub async fn personal_library(
app_data: web::Data<crate::AppState>,
req: HttpRequest,
) -> impl Responder {
response(app_data.core.get_personal_library(&username(req)).await)
}
#[post("/change_password")] #[post("/change_password")]
#[has_any_permission("user", "admin")] #[has_any_permission("user", "admin")]
pub async fn change_password( pub async fn change_password(